Skip to content

Instantly share code, notes, and snippets.

@jalapic
Created January 13, 2016 00:54
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 jalapic/2d85ad6d13fe790089df to your computer and use it in GitHub Desktop.
Save jalapic/2d85ad6d13fe790089df to your computer and use it in GitHub Desktop.
library(ggplot2)
library(dplyr)
data(mtcars)
sem <- function(x) sd(x)/sqrt(length(x)) #std error
mtcarsx <- mtcars %>% group_by(cyl) %>% summarize(meanx = mean(wt), semx = sem(wt)) %>% mutate(upr = meanx + semx, lwr = meanx - semx)
mtcarsx
ggplot(mtcarsx, aes(x=factor(cyl), y=meanx))+
geom_errorbar(aes(ymin=lwr, ymax=upr), width=.4)+
geom_line() +
geom_point() +
geom_point(data=mtcars, aes(factor(cyl), wt), size=3, color='gray77') +
theme_bw()
@jalapic
Copy link
Author

jalapic commented Jan 13, 2016

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment