::str_pad(c(0, 14, 178), width = 3, pad = 0) stringr
UQRUG 12
meeting
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:
This week’s TidyTuesday
Have fun with this week’s TidyTuesday: the rKenyaCensus dataset.
# Get the Data manually
<- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-01-19/gender.csv')
gender <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-01-19/crops.csv')
crops <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-01-19/households.csv') households
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