?本节学习「nature neuroscience」上一张配对条形图的绘制,数据为论文源数据,小编根据个人对数据的理解进行了绘图,结果与原图有所出入,整个过程仅参考。希望对各位观众老爷能有所帮助。「绘图代码会整合上传到会员交流群内」,购买过小编R数据可视化文档的朋友可在所加的会员群内获取下载,有需要的朋友可关注文末介绍加入交流群。 ?
?此图在基础条形上叠加了点的数据,并对不同处理间配对数据添加了连线及显著性标记。
library(tidyverse)
library(rstatix)
library(ggpubr)
df <- read_tsv("data.xls") %>% pivot_longer(-c(ID,Stimulation))
df_p_val1 <- df %>% group_by(name) %>%
wilcox_test(value ~ Stimulation) %>%
adjust_pvalue(p.col = "p", method = "bonferroni") %>%
add_significance(p.col = "p.adj") %>%
add_xy_position(x = "Stimulation", dodge = 0.8) %>%
mutate(xmin=1,xmax=2)
p1 <- df %>% filter(name=="No. Onsets") %>%
ggplot(aes(Stimulation,value)) +
stat_summary(fun.data =mean_sd,geom="errorbar",width=0.1)+
stat_summary(fun="mean",geom="bar",size=3,width = 0.5,aes(fill=Stimulation))+
geom_point()+
geom_line(aes(group=ID),color="grey",show.legend = F)+
stat_pvalue_manual(df_p_val1 %>% filter(name=="No. Onsets"),label = "p.adj.signif",label.size=6,hide.ns = F,
tip.length=0.01,color="black")+
scale_y_continuous(expand= expansion(mult = c(0,0.05)))+
scale_fill_manual(values=c("#7294D4","#F98400"))+
scale_color_manual(values=c("#7294D4","#F98400"))+
labs(x=NULL,y="No.walking Onsets")+
theme(plot.margin=unit(c(0.5,0,0.5,0.5),units=,"cm"),
panel.background = element_blank(),
plot.background = element_blank(),
axis.line = element_line(color = "black",size = 0.4),
axis.text.y = element_text(color="black",size=10),
axis.text.x =element_text(color="black",size=10),
legend.position = "none")