Hi Everyone this is my first time posting a question. I am new to using R to generate figures. I am following a tutorial to add p values to a bar plot from datanovia. I am able to successfully compute adjusted p values for several comparisons and now I am trying to plot them on a grouped bar chart. However the values are plotting in the position they appear the in dataframe and not matching to the name of the variable across the data.
For example if the fourth line of the data frame containing the p values shows a significant value then the fourth group in the bar plot will display that value, even though the x axis variable name doesn't match between the dataframes at the fourth position.
How do I correct this an ensure that the p values are displaying with their corresponding comparison?
This is the code to establish the p values.
library(ggpubr)
library(rstatix)
stat.test <- gg_means %>%
group_by(lipid) %>%
t_test(cor ~ Genotype) %>%
adjust_pvalue(method = "BH") %>%
add_significance("p.adj")
This is the code to create the bar plot
bp <- ggbarplot(gg_means, x = "lipid", y = "cor", add = "mean_sd", color= "Genotype",
palette = c("#00AFBB", "#E7B800"),
position = position_dodge(0.8),
ylab = "nmol/mg protein") +
theme(axis.text.x=element_text(angle=90,hjust=1,vjust=0.5))
and finally to add the pvalues to the bar plot
stat.test <- stat.test %>%
add_xy_position(fun = "mean_sd", x = "lipid", dodge = 0.8)
bp + stat_pvalue_manual(stat.test, label = "p.adj.signif", tip.length = 0.01)
The plot produced looks like 2 The arrows indicate where the values should be mapping.