❝本节继续来绘制nature上的一张图表,条形图进行显著性标记,数据为论文源数据,小编根据个人对数据的理解进行了分析绘图,结果与原图有所出入,整个过程仅供参考。希望对各位观众老爷能有所帮助❞
library(tidyverse)
library(scales)
library(ggh4x)
library(ggtext)
library(ggpubr)
library(rstatix)
sessionInfo()
df <- read_tsv("data.xls") %>%
unite(.,col="new_type",group,type,sep="_",remove = F,na.rm = F)
df$new_type <- factor(df$new_type,levels = df$new_type %>% unique())
df$group <- factor(df$group,levels = df$group %>% unique())
df_pval <- df %>%
t_test(value ~new_type) %>%
adjust_pvalue(p.col="p",method = "bonferroni") %>%
add_significance(p.col="p.adj",) %>%
add_xy_position(x="name") %>%
add_xy_position(x="new_type",dodge=0.8) %>%
filter(p.adj.signif !="ns") %>%
mutate(y.position=c(5.1,7,6.65,6.4))
df %>%
ggplot(aes(interaction(new_type,group),value))+
stat_summary(aes(fill=type),alpha=0.5,show.legend = F,
fun="mean",geom="bar",linewidth=0.4,width = 0.5,color="black")+
stat_summary(fun.data ="mean_se",geom="errorbar",width=0.2,linewidth=0.3,color="black")+
stat_pvalue_manual(df_pval,label = "p.adj.signif",hide.ns=F,
tip.length=0, label.size=4, color="black")+
guides(x = "axis_nested")+
theme_classic()+
theme(
axis.ticks.x=element_blank(),
axis.title.y=element_markdown(color="black",face="bold"),
axis.text.x=element_blank(),
axis.text.y=element_text(color="black",size=10,face="bold"),
plot.margin = margin(0.8,0.5,0.5,0.5,unit="cm"),
legend.position = "bottom",
legend.text = element_text(color="black",face="bold")
)