I am trying to plot electrical conductivity values of water for 10 different geographic districts as 10 separate boxplots on a single plot. I want to add asterisks to each boxplot indicating where values significantly differ from 400 (as opposed to significantly differ from each other, or from the mean of all values). My code currently looks like this:
well.data$ref <- 400
ggboxplot(well.data, x = "District", y = "Electrical_conductivity", color = "District",
add = "jitter", legend = "none") +
geom_boxplot() +
geom_text(aes(label = Sig, y = MaxWidth + 0.2), size = 10,
data = t_tests)+
geom_hline(yintercept=400, linetype="dashed", color = "red")+
stat_compare_means(method = "anova", label.y = 40)+
stat_compare_means(label = "p.signif", method = "t.test",
ref.group = "ref") +
theme(text = element_text(size = 20))
This generates the error:
Warning messages:
1: Computation failed in stat_compare_means()
:
missing value where TRUE/FALSE needed
2: Removed 10 rows containing missing values (geom_text).
My data looks roughly like this:
set.seed(42) ## for sake of reproducibility
n <- 100
well.data <- data.frame(
District=rep(LETTERS[1:10], n),
Electrical_conductivity=sample(200:500, n, replace=TRUE),
ref=400, n))