Professional Documents
Culture Documents
Ok, so I think I'm pretty close with this, but I'm getting an error when I try to construct my box plot
at the end. My goal is to place letters denoting statistical relationships among the time points
2 above each boxplot. I've seen two discussion of this on this site, and can reproduce the results
from their code, but can't apply it to my dataset.
Packages
2 library(ggplot2)
library(multcompView)
library(plyr)
Here is my data:
dput(WaterConDryMass)
structure(list(ChillTime = structure(c(1L, 1L, 1L, 1L, 2L, 2L,
2L, 2L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L), .Label = c("Pre_chill",
"6", "13", "24", "Post_chill"), class = "factor"), dmass = c(0.22,
0.19, 0.34, 0.12, 0.23, 0.33, 0.38, 0.15, 0.31, 0.34, 0.45, 0.48,
0.59, 0.54, 0.73, 0.69, 0.53, 0.57, 0.39, 0.8)), .Names = c("ChillTime",
"dmass"), row.names = c(NA, -20L), class = "data.frame")
Function:
# Create a data frame out of the factor levels and Tukey's homogenous group letters
plot.levels <- data.frame(plot.labels, labels = Tukey.labels[['Letters']],
stringsAsFactors = FALSE)
Boxplot:
https://stackoverflow.com/questions/44712185/tukeys-post-hoc-on-ggplot-boxplot 1/4
7/2/2019 r - Tukeys post-hoc on ggplot boxplot - Stack Overflow
ggtitle(expression(atop(bold("Water Content"), atop(italic("(Dry Mass)"), "")))) +
theme(plot.title = element_text(hjust = 0.5, face='bold')) +
annotate(geom = "rect", xmin = 1.5, xmax = 4.5, ymin = -Inf, ymax = Inf, alpha = 0.6,
fill = "grey90") +
geom_boxplot(fill = 'green2', stat = "boxplot") +
geom_text(data = generate_label_df(tHSD), aes(x = plot.labels, y = V1, label =
labels)) +
geom_vline(aes(xintercept=4.5), linetype="dashed") +
theme(plot.title = element_text(vjust=-0.6))
Error:
r ggplot2 boxplot
1 Answer
I think I found the tutorial you are following, or something very similar. You would probably be
best to copy and paste this whole thing into your work space, function and all, to avoid missing a
2 few small differences.
model=lm(WaterConDryMass$dmass~WaterConDryMass$ChillTime )
ANOVA=aov(model)
https://stackoverflow.com/questions/44712185/tukeys-post-hoc-on-ggplot-boxplot 2/4
7/2/2019 r - Tukeys post-hoc on ggplot boxplot - Stack Overflow
Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information
Bywith Stack
using our Overflow
site, you for Teams.
acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.
https://stackoverflow.com/questions/44712185/tukeys-post-hoc-on-ggplot-boxplot 3/4
7/2/2019 r - Tukeys post-hoc on ggplot boxplot - Stack Overflow
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and
our Terms of Service.
https://stackoverflow.com/questions/44712185/tukeys-post-hoc-on-ggplot-boxplot 4/4