其他
跟着nature communications学绘图之小提琴图添加显著性标记
欢迎关注R语言数据分析指南
❝本节来继续进行数据复现绘制小提琴图并添加显著性标记,下面通过一个小例子来进行展示;数据及代码会同步上传到「VIP群」已经加群的观众老爷可以直接获取,小编的VIP群目前已经上传「公众号文档数据+代码约160余篇」,有需要加群的欢迎「先点击发消息」之后
❞公众号右下角添加微信
「付费99元」邀请进群
❝A highly conserved core bacterial microbiota with nitrogen-fixation capacity inhabits the xylem sap in maize plants
❞
往期内容
加载R包
library(tidyverse)
library(magrittr)
定义颜色
col=c("#1F78B4","#33A02C","#FB9A99","#E31A1C","#FDBF6F","#B2DF8A","#A6CEE3")
定义因子
df <- read_tsv("data.xls")
df$Compartments <- factor(df$Compartments,levels = c("BS","RS","RE","VE","SE","LE","P"))
定义字母标记
text <- df %>% group_by(Compartments) %>% summarise(max(`Shannon index`)) %>%
set_colnames(c("group","value")) %>%
mutate(value=value+0.3,p=c("a","b","c","g","f","e","d"))
数据可视化
df %>% set_colnames(c("sample","value","group")) %>%
ggplot(aes(group,value,fill=group))+
geom_violin(position = position_dodge(width = 0.1), scale = 'width')+
stat_boxplot(geom="errorbar",position = position_dodge(width = 0.1),width=0.1)+
geom_boxplot(alpha=1,outlier.size=0, size=0.3, width=0.3,fill="white")+
geom_text(data=text,aes(label=p,y=value),size=5,
color=c("#1F78B4","#33A02C","#FB9A99","#E31A1C","#FDBF6F","#B2DF8A","#A6CEE3"))+
labs(x=NULL, y="Shannon index")+
scale_fill_manual(values = col)+
theme_test() +
theme(axis.text.x = element_text(size = 8,color="black"),
axis.text.y = element_text(size = 8,color="black"),
axis.title.y= element_text(size=12,color="black"),
axis.title.x = element_text(size = 12,color="black"),
legend.title=element_blank(),
legend.key=element_blank(),
legend.box.background = element_blank(),
legend.text = element_text(color="black",size=8),
legend.spacing.y = unit(0.3,"cm"),
legend.spacing.x=unit(0.1,'cm'),
legend.key.width=unit(0.3,'cm'),
legend.key.height=unit(0.3,'cm'),
legend.background=element_blank(),
legend.position=c(0.99,0.9999),legend.justification=c(1,1))
数据获取
❝本节介绍到此结束,需要获取小编之前绘图文档数据及代码的欢迎加入小编的
❞2022年VIP交流群,付费99元
,群内会同步上传公众号文档代码;目前已上传2021-2022约160篇文档代码
;添加小编微信时,请备注单位-方向-姓名以及来意以便高效处理
, 本篇文档数据可从文章中进行下载
免费交流群
欢迎大家扫描下方二维码加入「QQ交流群」,与全国各地上千位小伙伴交流