Created
March 1, 2017 18:39
-
-
Save karawoo/f5961143a5aafe29bf62df682c5f79ac 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
## 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