Skip to content

Instantly share code, notes, and snippets.

@timcdlucas
Created December 2, 2016 12:48
Show Gist options
  • Save timcdlucas/1fb6c4e4ebc4de0ac42c6458bfa00572 to your computer and use it in GitHub Desktop.
Save timcdlucas/1fb6c4e4ebc4de0ac42c6458bfa00572 to your computer and use it in GitHub Desktop.
violin and CIs
df1 <- data.frame(y = rnorm(100), x = letters[1:2])
df2 <- data.frame(aggregate(. ~ x, df1, mean),
upperCI = aggregate(. ~ x, df1, function(x) quantile(x, 0.025))[, 2],
lowerCI = aggregate(. ~ x, df1, function(x) quantile(x, 0.975))[, 2])
ggplot() +
geom_violin(data = df1, aes(x = x, y = y)) +
geom_errorbar(data = df2, aes(x = x, ymax = upperCI, ymin = lowerCI), width = 0.5) +
geom_point(data = df2, aes(x, y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment