This is largely a note to my future self.
Everyone knows boxplots don’t show mean values but many want them to be there.
Here are four options. In our 2022 class, option C was picked as the clearest of the four.
a <- ggplot(na.omit(df1), aes(x = wrkctra, y = imbgeco)) +
geom_boxplot() +
labs(x = "boxplot") +
theme_minimal()
b <- ggplot(na.omit(df1), aes(x = wrkctra, y = imbgeco)) +
geom_jitter(position = position_jitter(0.2), alpha = 0.2) +
# mean points
stat_summary(
fun = mean,
geom = "point",
shape = 18,
size = 3,
color = "red") +
labs(x = "jittered strip plot with mean") +
theme_minimal()
d <- ggplot(na.omit(df1), aes(x = wrkctra, y = imbgeco)) +
geom_jitter(position = position_jitter(0.2), alpha = 0.2) +
stat_summary(
fun = mean,
geom = "crossbar",
width = 0.3,
color = "red") +
labs(x = "jittered strip plot with mean bars") +
theme_minimal()
library(ggdist)
e <- ggplot(na.omit(df1), aes(wrkctra, imbgeco)) +
stat_dotsinterval(layout = "swarm") +
labs(x = "swarmplot") +
theme_minimal()
library(patchwork)
(a + b) / (d + e) + plot_annotation(tag_levels = 'A')