Skip to content

Instantly share code, notes, and snippets.

@fdabl
Created October 17, 2016 12:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fdabl/37b0250959d5b4c64b0a9193bf0646c9 to your computer and use it in GitHub Desktop.
Save fdabl/37b0250959d5b4c64b0a9193bf0646c9 to your computer and use it in GitHub Desktop.
# for https://www.facebook.com/efpsa.jeps/posts/1278843852167100
library('ggplot2')
library('gridExtra')
set.seed(1774)
# generate data
A = c(rnorm(20, 20, 4), rnorm(20, 40, 4)) # mixture distribution
B = rt(30, 1) + 30 # from a heavy-tailed distribution (Cauchy)
C = c(25, 35, 33) # just three data points
dat = data.frame(
score = c(A, B, C),
group = rep(c('A', 'B', 'C'), c(40, 30, 3))
)
gdat = dat %>%
group_by(group) %>%
summarize(mean = mean(score),
se = sd(score) / sqrt(length(score)))
p1 = ggplot(gdat, aes(x = group, y = mean, fill = group)) +
geom_bar(stat = 'identity') +
geom_errorbar(aes(ymin = mean - se, ymax = mean + se), width = .2) +
ggtitle('Dynamite Plot (Mean + SE)') +
theme(plot.title = element_text(face = 'bold', size = 18)) +
ylim(0, 50)
p2 = ggplot(dat, aes(x = group, y = score, fill = group)) +
geom_boxplot() +
geom_point() +
ggtitle('Boxplot + Datapoints') +
theme(plot.title = element_text(face = 'bold', size = 18)) +
ylim(0, 50)
grid.arrange(p1, p2, ncol = 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment