1

I'm testing for a relationship between different crosses of blueberry varieties and their adjusted fruit mass (a proxy for realized yield). I created a mixed linear model and found a significant effect but I wanted to know which crosses are best. So, I used emmeans to perform a post hoc test with Tukey. I now want to add those p-values to my boxplot (or stars to indicate a significant difference) but I am struggling on how to do this. This code works but it results in brackets with no star/value/etc and still includes capital "NS". Is there a better way to approach this? I've included a photo of my data for reference.

sm <- lmer(adj_fruitmass ~ pair + (1|plantid), data = pilot)

# Post-hoc test 
cmpr <- list(c("Bluecrop", "Duke"),
             c("Bluecrop", "Reka"), 
             c("Duke", "Bluecrop"),
             c("Duke", "Reka"))

emmeans(sm, pairwise ~ pair, adjust = "tukey")

# Change one NA to zero to fix order of boxplots
pilot$adj_fruitmass[is.na(pilot$adj_fruitmass)] <- 0

# Add post-hoc p-values to boxplot
pilot %>%
ggplot(aes(x = reorder(Pollen_donor, adj_fruitmass), y = adj_fruitmass, na.rm = T)) +
  geom_boxplot() +
  geom_point() +
  labs(x = "Pollen donor", y = "Adjusted fruit mass") +
  theme_classic() +
  facet_grid(~Variety) +
  stat_compare_means(comparisons = cmpr, 
                     label = "p.signif", 
                     hide.ns = TRUE,
                     tip.length = 0.01,
                     symnum.args = list(cutpoints = c(0, 0.0001, 0.001, 0.01, 0.05, 1), 
         symbols = c("****", "***", "**", "*", "ns")))
  • 1
    I think trying to add information about pairwise comparisons to a plot of means an create clutter, and I suggest it may not be worth it. For example if there are 4 groups, then there are 6 comparisons. 5 means has 10 comparisons, and 6 means has 15. What if you just have a plainer plot of the means, and a separate display -- or just a table -- for comparisons? Both will be easier to read. – Russ Lenth Jul 23 '22 at 01:05

0 Answers0