Created
October 17, 2016 12:43
-
-
Save fdabl/37b0250959d5b4c64b0a9193bf0646c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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