Skip to content

Instantly share code, notes, and snippets.

@karawoo
Created March 1, 2017 18:39
Show Gist options
  • Save karawoo/f5961143a5aafe29bf62df682c5f79ac to your computer and use it in GitHub Desktop.
Save karawoo/f5961143a5aafe29bf62df682c5f79ac to your computer and use it in GitHub Desktop.
## Load tidyverse package, which contains ggplot2, dplyr, tidyr, etc.
library("tidyverse")
## Create some data
set.seed(432)
dat <- tibble(fert = c(rnorm(n = 10, mean = 0.6, sd = 0.2),
rnorm(n = 10, mean = 0.4, sd = 0.2)),
treat = rep(c("25-25", "28-28"), each = 10))
## Plot boxplots with points on top + yellow X for mean & legend
ggplot(dat, aes(x = treat, y = fert)) +
geom_boxplot(aes(fill = treat), width = 0.5) +
geom_point(size = 3) +
## Add means (with legend)
stat_summary(fun.y = "mean", aes(shape = "mean"), colour = "yellow",
geom = "point", size = 4) +
scale_shape_manual("", values = c("mean" = "x"))
## Plot boxplots with points on top + yellow X for mean
ggplot(dat, aes(x = treat, y = fert)) +
geom_boxplot(aes(fill = treat), width = 0.5) +
geom_point(size = 3) +
## Add means (no legend)
stat_summary(fun.y = "mean", pch = 4, colour = "yellow",
geom = "point", size = 4)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment