It’s #TalkLikeAPirateDay! Since we have plenty of ARRRRR experience already, we’re analyzing pirates instead! Female pirates tend to be older and have much shorter beards than male pirates, but pirates of all genders drink Grogg like fish!
Want to recreate this analysis!? Follow along with the code below!
install.packages("yarrr")
install.packages("tidyverse")
install.packages("cowplot")
library(yarrr)
library(tidyverse)
library(cowplot)
pirates_stats <- pirates %>%
mutate(sex = tools::toTitleCase(sex)) %>%
select(id, sex, age, height, tattoos, parrots, beard.length, grogg) %>%
gather(key = variable, value = value, 3:ncol(.)) %>%
mutate(variable = tools::toTitleCase(gsub("\\.", " ", variable))) %>%
mutate(variable = factor(variable, labels = c("Age (Years)", "Beard Length (cm)", "Grogg (mugs/day)", "Height (cm)", "Parrots (#)", "Tattoos (#)")))
pirate.cols <- str_sub(piratepal(palette = "cars", trans = 0), end = 7)
p1 <- ggplot(data = pirates_stats, aes(x = sex, y = value, fill = sex)) +
geom_boxplot() +
facet_wrap(~variable, scales = "free") +
scale_fill_manual(values = pirate.cols[1:3]) +
theme_minimal(14) +
theme(
legend.position = "off"
) +
labs(
title = "Distribution of Pirate Characteristics by Gender",
subtitle = "Based on a survey of 1000 pirates as provided by the yarrr package"
) +
xlab("Sex") +
ylab("Value")
p1