Question Details

No question body available.

Tags

r ggplot2 boxplot

Answers (1)

March 18, 2026 Score: 3 Rep: 26,698 Quality: Medium Completeness: 80%

Here's one potential solution calculating the relative position beforehand, noting that the boxplot shows the median, and you are calculating/printing the mean and sd in your code:

library(tidyverse)

data.boxplot % groupby(Component, Label) %>% mutate(bottomlimit = boxplot.stats(Score)[[1]][1] - 1, labels = paste( "M =", round(mean(Score), 2), "\n", "SD =", round(sd(Score), 2), "\n")) %>% ungroup() %>% ggplot(aes(x = Component, y = Score, fill = Label)) + geomboxplot(outliers = FALSE) + scalefillmanual(values = c("#FF5F1F", "#1FC0FF")) + statsummary(geom = "text", aes(y = bottomlimit, x = Component, label = labels), vjust = 1, position = positiondodge(width = 0.8)) + themeclassic() + scaleycontinuous(limits = c(0, 100), expand = expansion(mult = c(0, 0))) #> No summary function supplied, defaulting to meanse()

example.png

Created on 2026-03-18 with reprex v2.1.1.9000