visualizationanovap-valueggpubrtukey

Grouped barplots with error bars and pvalue pairwise comparisons


Am new to stackoverflow and would love some help.

I have a dataset as below. I would like to create a barplot showing pairwise comparisons between treatment groups as shown but with significance stars added to pvalues on top. I would also like to scale the y-axis from 0 to 100 on a break (scale) of 10.

df_ss <- structure(list(Plant = structure(c(5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), levels = c("Actelic", 
"cv", "DCM", "None", "ss"), class = "factor"), Trt = structure(c(3L, 
3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 
7L, 7L, 7L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 
6L, 6L, 6L, 7L, 7L, 7L, 7L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 
5L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 3L, 3L, 3L, 3L, 4L, 
4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 3L, 
3L, 3L, 3L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 7L, 
7L, 7L, 7L), levels = c("Untreated control", "Solvent control", 
"2g", "4g", "6g", "8g", "10g", "Positive control"), class = c("ordered", 
"factor")), Time = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L), levels = c("X6hr", 
"X24hr", "X48hr", "X72hr", "X96hr"), class = "factor"), PR = c(0, 
10, 0, 10, 0, 10, 10, 0, 20, 0, 10, 0, 20, 10, 20, 0, 10, 20, 
10, 20, 0, 10, 0, 10, 10, 10, 10, 0, 20, 10, 10, 10, 20, 10, 
20, 10, 20, 20, 20, 20, 10, 10, 10, 20, 10, 20, 20, 10, 30, 10, 
20, 10, 30, 20, 20, 20, 20, 30, 20, 20, 20, 20, 10, 20, 30, 30, 
30, 10, 30, 20, 20, 30, 30, 30, 30, 20, 40, 30, 50, 40, 30, 20, 
20, 20, 40, 30, 30, 20, 30, 40, 30, 30, 60, 30, 40, 30, 50, 60, 
60, 50)), row.names = c(17L, 18L, 19L, 20L, 25L, 26L, 27L, 28L, 
33L, 34L, 35L, 36L, 41L, 42L, 43L, 44L, 49L, 50L, 51L, 52L, 69L, 
70L, 71L, 72L, 77L, 78L, 79L, 80L, 85L, 86L, 87L, 88L, 93L, 94L, 
95L, 96L, 101L, 102L, 103L, 104L, 121L, 122L, 123L, 124L, 129L, 
130L, 131L, 132L, 137L, 138L, 139L, 140L, 145L, 146L, 147L, 148L, 
153L, 154L, 155L, 156L, 173L, 174L, 175L, 176L, 181L, 182L, 183L, 
184L, 189L, 190L, 191L, 192L, 197L, 198L, 199L, 200L, 205L, 206L, 
207L, 208L, 225L, 226L, 227L, 228L, 233L, 234L, 235L, 236L, 241L, 
242L, 243L, 244L, 249L, 250L, 251L, 252L, 257L, 258L, 259L, 260L
), class = "data.frame")


library(ggpubr)
#> Loading required package: ggplot2
#> Warning: package 'ggplot2' was built under R version 4.3.3

df_ss_6hr <- df_ss[df_ss$Time %in% "X6hr", ]

bxp6 <- ggbarplot(df_ss_6hr, x = "Trt", y = "PR", fill = "Trt", color = "Trt",width = 0.5, 
                 palette = c("#4DAF4A","dodgerblue4","olivedrab3", "darkgoldenrod1","#00AFBB")
)+
    scale_y_continuous(expand = expansion(mult = c(0.05, 0.10)))



`The scale limit is not 100`



bxp6 +
    geom_pwc(
        aes(group = Trt), tip.length = 0,label.size = 2.5, 
        method = "tukey_hsd", label = "p.adj.format",
        bracket.nudge.y = 18,step.increase=3
    ) +
    scale_y_continuous(expand = expansion(mult = c(0, 0.1)))
}
#> Scale for y is already present.
#> Adding another scale for y, which will replace the existing scale.

I have tried many solutions without success.

scale_y_continuous(breaks = breaks_width(10))

Solution

  • … with significance stars added to pvalues …

    label = "{p.adj.format}{p.adj.signif}"
    

    … scale the y-axis from 0 to 100 on a break (scale) of 10

    scale_y_continuous(breaks=0:10*10)
    

    With bracket.nudge.y=5, step.increase=.5 I get: