Please find the data that I need to visualize here. I want to reveal if there is any variable that is significantly different than the reference variable. I draw the barplot, list the variables, which will be compared with each other, make the statistics and draw the significance lines as you see below. It is all good up to this point.
library(tidyverse)
library(here)
library(readxl)
library(ggforce)
library(ggplot2)
library(ggsignif)
library(ggpubr)
library(rstatix)
data <- read.csv(here("data", "data.csv"), sep = ";")
# List the variables to be compared with each other in pairwise comparison
my_comparisons <- list( c("%0", "250 µg/ml"), c("%0", "100 µg/ml"), c("%0", "50 µg/ml"), c("%0", "25 µg/ml"))
#Statistics
stat.test <- data %>%
t_test(OD ~ Material_Concentration, p.adjust.method = "bonferroni", comparisons = my_comparisons) %>%
add_significance("p.adj")
stat.test
# add significance
stat.test <- stat.test %>%
add_xy_position(x = "Material_Concentration")
#plot the data
p <- ggplot(data, aes(Material_Concentration, OD, colour = Material_Concentration))+
stat_summary(fun = mean, geom = "col", aes(fill = Material_Concentration), show.legend = FALSE)+
stat_summary(fun.data = mean_se, geom = "errorbar", width = 0.2, show.legend = FALSE)+
xlab("Treatment Concentrations")+
ylab("Average OD")+
theme(panel.background = element_blank(), plot.title = element_text(color="red", size=40, face="bold.italic", hjust = 0.5),
axis.text.x = element_text(size = 20, angle = 45, hjust = 1),
axis.text.y = element_text(size = 15),
axis.title.y = element_text(size = 15),
axis.title.x = element_text(size = 15))+
stat_pvalue_manual(stat.test, label = "p.adj.signif")
p
However, when I rearrange the positions of variables on x-axis, by using scale-x-discrete
the x-positions of significance lines do not change.
library(tidyverse)
library(here)
library(readxl)
library(ggforce)
library(ggplot2)
library(ggsignif)
library(ggpubr)
library(rstatix)
data <- read.csv(here("data", "data.csv"), sep = ";")
# List the variables to be compared with each other in pairwise comparison
my_comparisons <- list( c("%0", "250 µg/ml"), c("%0", "100 µg/ml"), c("%0", "50 µg/ml"), c("%0", "25 µg/ml"))
#Statistics
stat.test <- data %>%
t_test(OD ~ Material_Concentration, p.adjust.method = "bonferroni", comparisons = my_comparisons) %>%
add_significance("p.adj")
stat.test
# add significance
stat.test <- stat.test %>%
add_xy_position(x = "Material_Concentration")
#plot the data
p <- ggplot(data, aes(Material_Concentration, OD, colour = Material_Concentration))+
stat_summary(fun = mean, geom = "col", aes(fill = Material_Concentration), show.legend = FALSE)+
stat_summary(fun.data = mean_se, geom = "errorbar", width = 0.2, show.legend = FALSE)+
xlab("Treatment Concentrations")+
ylab("Average OD")+
theme(panel.background = element_blank(), plot.title = element_text(color="red", size=40, face="bold.italic", hjust = 0.5),
axis.text.x = element_text(size = 20, angle = 45, hjust = 1),
axis.text.y = element_text(size = 15),
axis.title.y = element_text(size = 15),
axis.title.x = element_text(size = 15))+
scale_x_discrete(limits = c("250 µg/ml", "100 µg/ml", "50 µg/ml", "25 µg/ml", "%0", "%10"))+
stat_pvalue_manual(stat.test, label = "p.adj.signif")
p
Positioning of significance lines are not correct in this image
How can I solve this problem? I would be really glad if you may reveal my mistake.
Thank you