0

I have photosynthetic data I am trying to plot, with plant development stage on the x-axis, and the average yield on the y-axis. I also have four different plants I took these measurements on, so I used facet_wrap(~Line.x) to create four plots, each representing that particular line's change in yield over the development stages. Each line had five treatments applied to influence yield at each stage. I ran ANOVA and tukey analysis to label each boxplot with their respective letters.

Comparisons were made within a particular plant, in a particular development stage, between the treatments.

I have everything on the plot already, including the tukey letters. However, I do not know how to adjust my geom_text line so that R know where to put letters go among the treatments.

Here is the current code I have, I made adjustments from geom_text but haven't gotten it right.

ggplot(data_new, aes(DevelopmentStage, A.µmol.m...s..., fill=Day.Night.C.x)) + 
geom_boxplot() +
labs(x="Line (plant), development stage, and treatment", y="Average yeild") +
theme_bw() + 
theme(panel.grid.major = element_blank(), panel.grid.minor = element_blank(),
text=element_text(size=20)) +
geom_text(data = A.line.tukey.allstages, aes(x = DevelopmentStage, y = quant, label = Tukey), size = 5, vjust=-1.25, hjust =-1)+
facet_wrap(~Line.x)+
labs(title='Effect of treatments on net yield' ,
caption = 'Groups sharing the same letters are not statistically different from one another at the p=0.05 level',
fill= 'Treatment')

Nearly complete figure, tukey letters are in the correct facet and above the correct line, but not above their respective treatment box

Example subset of data:

structure(list(Yield = c(8.151375452, 8.382517873, 8.44283403, 10.31881757, 10.3557304, 9.928674142, 10.33451677, 10.69507697, 10.57664686, 11.16575551, 11.04700581, 11.23337648, 6.543935774, 6.572356108, 7.345439724, 12.53070112, 12.25825808, 12.3404997, 13.23889684, 13.2798362, 12.49735692, 11.87736011, 11.85216308, 11.59254363, 9.284810253, 9.011053873, 9.173928237, 14.05942045, 13.78539868, 14.09753387, 13.79196207, 13.27845743, 13.42134734, 13.41913518, 15.27662039, 15.10059174, 11.15805372, 12.39770032, 12.45950119, 11.94798457, 12.61388394, 12.14116668, 12.21064804, 6.69254258, 12.52026321, 12.88836323, 13.60539121, 13.22586637), Days.after.sow.x = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), .Label = c("21", "25", "28", "32", "35", "42"), class = "factor"), Day.Night.C.x = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L), .Label = c("25/15", "20/25", "25/25", "35/20", "35/25"), class = "factor"), Rep = structure(c(1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 2L, 3L, 4L, 5L, 6L, 7L, 17L, 18L, 19L, 2L, 3L, 4L, 1L, 2L, 3L, 4L, 5L, 6L, 1L, 2L, 3L, 9L, 10L, 11L, 3L, 4L, 5L, 6L, 7L, 8L, 1L, 2L, 3L, 1L, 2L, 3L), .Label = c("1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", "36"), class = "factor"), Line.x = structure(c(4L, 4L, 4L, 2L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 4L, 4L, 4L, 2L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 4L, 4L, 4L, 2L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L, 4L, 4L, 4L, 2L, 2L, 2L, 3L, 3L, 3L, 1L, 1L, 1L), .Label = c("Manatee", "60183", "Bambino", "60179"), class = "factor"), DevelopmentStage = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("Seedling", "Juvenile", "Mature", "Harvest"), class = "factor")), row.names = c(1L, 2L, 3L, 37L, 38L, 39L, 73L, 74L, 75L, 109L, 110L, 111L, 146L, 147L, 148L, 185L, 186L, 187L, 233L, 234L, 235L, 254L, 255L, 256L, 289L, 290L, 291L, 328L, 329L, 330L, 361L, 362L, 363L, 405L, 406L, 407L, 435L, 436L, 437L, 474L, 475L, 476L, 505L, 506L, 507L, 541L, 542L, 543L), class = "data.frame")

  • Excuse me, Yield data ** – Hannah Mather Jun 09 '23 at 20:44
  • 1
    Welcome to SO! It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data best shared via `dput()`. – stefan Jun 10 '23 at 07:58
  • This said. If you want to align the text labels with the individual box plots try with `geom_text(...., position = position_dodge(width = .75))` to dodge the labels by the same amount as the boxplots. `geom_text` uses `position = "identity"` by default. Hence by default the labels will be placed on to of each other. – stefan Jun 10 '23 at 08:01
  • @stefan thank you for the advice! However I am still having some issue with the code. Here is a subset of my data set: – Hannah Mather Jun 12 '23 at 14:09
  • @stefan I believe I was able to provide a data subset. Your previous code did help a bit, but things are still a bit off. If you happen to have the time and see this, I'd very much appreciate any advice ! :) – Hannah Mather Jun 19 '23 at 15:48

0 Answers0