0

I plotted my data and integrated the p-value into my plot, but unfortunately in some cases the statistical significant differences between two groups are shown double in the plot, but I only want it to be shown once for each comparisonenter image description here

I tried to delete one bracket or even one comparison but I could not find a way to specifically delete one of two brackets, which are double. If I use a higher number of "n", than the double brackets disappear.

#Lactate Experiment ##Prepare Dataset

Lactate.data_long <- Lactate.data %>%
                                    gather(key = "variable", value = "value", -Tube.Nr., -Oxygen.condition, -Cell.type, -Experiment, -Day, -Well, -Label)

Lactate.data_long$variable <- factor(Lactate.data_long$variable, levels = c("Lactate", "Glucose"))

levels(Lactate.data_long$variable) <- c("Lactate", "Glucose")

Lactate.data_long <- Lactate.data_long %>% 
                        dplyr::rename(test = variable)

##Statistics Metabolites (all Wells)

stat_Metabolites.test <- Lactate.data_long %>%
                                  group_by(Oxygen.condition, Day, test) %>%
                                  dunn_test(value ~ Cell.type) %>%
                                  add_xy_position(x = "test") %>%
                                  arrange(p.adj)
stat_Metabolites.test

##Statistics Metabolites (Experiment)

stat_Metabolites.test.exp <- Lactate.data_long %>%
                                  group_by(Oxygen.condition, Day, test, Experiment) %>%
                                  dunn_test(value ~ Cell.type) %>%
                                  add_xy_position(x = "test") %>%
                                  arrange(p.adj)
stat_Metabolites.test.exp

##Plot

Lactate_plot <- ggplot(Lactate.data_long, aes(x = test, y = value)) +
                    geom_boxplot(aes(fill = Cell.type),
                                  size = 0.8,
                                  alpha = 0.6,
                                 color = "black",
                                 lwd = 0.2,
                                 outlier.shape = NA,
                                 position = position_dodge(width = 0.75)) +
                    stat_summary(fun = mean,
                               geom = "point",
                               size = 1.7,
                               fill = "white",
                               shape = 23,
                               color = "black",
                               alpha = 1,
                               aes(group = Cell.type),
                               position = position_dodge(width = 0.75)) +
#                    coord_cartesian(ylim = c(0, 50)) +
#                    scale_y_continuous(breaks=seq(0,50, 5)) +
                    scale_fill_manual(values = colors_Lactate) +
                    ylab(expression(bold(paste("concentration")))) +
                    # geom_label(data = prolif_des.stat, aes(x = time, group = celltype, label = paste0("n=", n),
                    #                                        y = 0),
                    #            position = position_dodge(width = 0.75),
                    #            size = 2.5,
                    #            fontface = "bold",
                    #            color = "gray40") +
                    facet_grid(Oxygen.condition ~ Day) +
                    theme_bw() + 
                    stat_pvalue_manual(stat_Metabolites.test.exp,
                                                 label = "p.adj.signif",
                                                 size = 5,
#                                                 y.position = 40,
                                                 bracket.size = 0.3,
                                                 remove.bracket = FALSE,
                                                 hide.ns = TRUE) +
                              theme(legend.title = element_blank(),
                                    #legend.position = c(0.1, 0.9),
                                    legend.position = "top",
                                    legend.text = element_text(size = 7, face = "bold"),
                                    legend.text.align = 0,
                                    legend.background = element_blank(), 
                                    legend.key = element_blank(),
                                    panel.border = element_rect(colour = "black", size=.5),
                                    axis.title.y = element_text(size= 9, face = "bold", colour = "black"),
                                    axis.title.x = element_blank(),
                                    axis.ticks = element_line(colour = "black", size = .3),
                                    panel.grid.minor = element_blank(),
                                    panel.grid.major = element_line(size=0.2),
                                    axis.text.y = element_text(size = 7, face = "bold", colour = "black"),
                                    axis.text.x = element_text(size = 9, face = "bold", colour = "black"),
                                    axis.ticks.length=unit(.5, "mm"),
                                    strip.text = element_text(color = "black", size = 9, face = "bold"),
                                    panel.spacing = unit(1, "mm"))
Lactate_plot

#ggsave(paste0(export.dir, "_Lactate_plot.pdf"), plot = Lactate_plot, height = 4.5, width = 9, units = "cm")
  • Please provide enough code so others can better understand or reproduce the problem. – Community Jul 28 '23 at 09:53
  • 1
    Could you please share the data used `dput(yourDataFrame)` and also share the code used for plotting so that we can reproduce your plots and find a solution – Yacine Hajji Jul 28 '23 at 09:53
  • 2
    Could you please make this a *minimal* reproducible example and only include minimally sufficient code to recreate the problem? Much of this is not needed and having to weed through deters folks from wanting to help. Good luck! – jpsmith Jul 28 '23 at 10:39
  • How do I upload the data? – David Cerqueira Jul 28 '23 at 11:23
  • Hi David, welcome to Stack Overflow. What @jpsmith and Yacine are requesting is that you simplify the data so that you remove all of the extraneous data and only share the minimum number of variables that can reproduce your problem of double brackets. This will take some experimentation with your data. You do not have to upload the data. You can use `dput(head(your.data))` like Yacine is suggesting. For example, you could edit your post and show the results of `dput(stat_Metabolites.test.exp)`. It is difficult to give you advice without seeing what data is being used by `ggplot`. – David Jul 28 '23 at 12:21
  • About uploading and general, see: https://stackoverflow.com/help/minimal-reproducible-example . That said, `stat_Metabolites.test.exp` contains a 4-way comparison (oxygen, day, test, experiment) which **appears to mismatch** with the 4-way layout of your plot (oxygen, day, test (?), cell type). That way it could happen that one "drawer" of your plot has to accomodate more than one test result. Hard to tell without sample data, though. – I_O Jul 28 '23 at 12:24
  • 1
    Also see [here](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) for tips specific to R – jpsmith Jul 28 '23 at 12:32

0 Answers0