UQRUG 12

meeting
Published

January 25, 2021

2021-01-25: UQRUG 12

This is our first anniversary! UQRUG has one year!!

Attendees and questions

  • Paula Martinez I’m a keen R user, I also founded R Ladies Brisbane and you are welcome to join https://www.meetup.com/rladies-brisbane/
  • Kathy: Phd SSI, wants to learn more R
  • David Green: RCC, hacky hour
  • Stéphane Guillou (Library): keen to start UQRUG again for 2021!
  • Phoebe: Just hanging to learn something :)
  • Isabel (IMB), microbiologist, here to meet other R folks and learn :)

Naming things

Paula presented these very useful slides by Jenny Bryan about how to name files and directory for profit!

  • Link to the slides: https://speakerdeck.com/jennybc/how-to-name-files
  • Steph couldn’t remember what that padding function was, but discovered stringr has a great one, str_pad(): https://www.rdocumentation.org/packages/stringr/versions/1.4.0/topics/str_pad

For example, try this:

stringr::str_pad(c(0, 14, 178), width = 3, pad = 0)

This week’s TidyTuesday

Have fun with this week’s TidyTuesday: the rKenyaCensus dataset.

# Get the Data manually

gender <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-01-19/gender.csv')
crops <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-01-19/crops.csv')
households <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-01-19/households.csv')

Resources shared

  • RStudio Global conference was last week. Recordings will be available on the RStudio website soon.
    • Stéphane really recommends the presentation: How to do things with words: learning to program in R with a “communicative approach”, by Riva Quiroga
  • Main R terms for beginners: https://gitlab.com/stragu/DSH/-/blob/master/R/terminology.md
    • Don’t hesitate to send Steph some feedback!
  • Converting Windows style to Unix: https://support.nesi.org.nz/hc/en-gb/articles/218032857-Converting-from-Windows-style-to-UNIX-style-line-endings
  • Notepad++, useful (open source) text editor which has an option to change file endings: https://notepad-plus-plus.org/
  • theme_publish(), a ggplot2 theme provided by the package envalysis: https://rdrr.io/github/zsteinmetz/envalysis/man/theme_publish.html
  • https://rstudio.com/resources/webinars/ to watch the presentations from the last RStudio conferences
  • Visual Markdown editor in the new RStudio 1.4: https://blog.rstudio.com/2020/09/30/rstudio-v1-4-preview-visual-markdown-editing/
  • Bar plots guide: https://michaeltoth.me/detailed-guide-to-the-bar-chart-in-r-with-ggplot.html
  • Two-way anova: http://www.sthda.com/english/wiki/two-way-anova-test-in-r
  • Other packages built on top of ggplot2: https://exts.ggplot2.tidyverse.org/gallery/

Phoebe’s faceted visualisation

Phoebe needed to reshape her dataset to then visualise it in separate facets.

 CBMI %>% 
        select(Gender, contains("BMI")) %>% 
        pivot_longer(contains("BMI"), names_to="Year", values_to="BMI") %>% 
        mutate(Year=fct_inorder(Year)) %>% 
        ggplot(aes(x=Gender, y=BMI)) + 
        geom_boxplot() +
        facet_grid(cols=vars(Year)) +
        theme_pubr()

Recommendations for Katherine’s bar chart

library(ggplot2)

# useful geometries:
geom_bar() # height of a bar is a count
geom_col() # if you already have the value for the height of the bar

# to have bars side by side, change the position to "dodge"
# (instead of the default "stack"), for example:
ggplot(mpg, aes(x = as.character(cyl), fill = class)) +
  geom_bar(position = "dodge")

# for adding error bars
geom_errorbar()
# you have to provide the values for the size of the bars (xmin, xmax)
# and their position (x, y)

You might find that an extra package to add on top of ggplot2 will do the hard work for you. Many are listed here: https://exts.ggplot2.tidyverse.org/gallery/

More resources: * Bar plots guide: https://michaeltoth.me/detailed-guide-to-the-bar-chart-in-r-with-ggplot.html * Two way anova: http://www.sthda.com/english/wiki/two-way-anova-test-in-r