其他
论文图表复现—箱线图
今天,我们来对下面这篇文章中的Fig.2b及Fig.2c中的图进行复现:
设置工作环境
#设置工作环境
rm(list=ls())
setwd("D:\\Fig2")
#加载包
library(ggplot2)
Fig.2b
1、加载数据
df1 <- read.table("df_1.txt",header = T, check.names = F)
head(df1)
2、绘制箱线图
p1 <- ggplot(data =df1, aes(x=Comparison, y=Dissimilarity)) +
geom_boxplot(aes(fill = Comparison), width = 0.8)
3、添加散点图
p1+geom_point(position='jitter',shape=1, alpha=.5)
4、主题设置
p1+theme_bw() + theme(aspect.ratio = 1)+
geom_point(position='jitter',shape=1, alpha=.5)+
ylab("Bray-Curtis dissimilarity\n") +
theme(axis.line = element_line(colour = "black"),
legend.position = 'none',
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
panel.background = element_blank()) +
theme(plot.title = element_text(size = 20,hjust = 0.5, face='bold')) +
theme(axis.title.x = element_text(size = 10,hjust = 0.5, face='bold')) +
theme(axis.title.y = element_text(size = 10,hjust = 0.5, face='bold')) +
theme(axis.text.x = element_text(angle = 0, hjust = 0.95, vjust=0.4,size=10, face='bold',color='black'))+
theme(axis.text.y = element_text(size=10, face='bold',color='black'))+
scale_y_continuous(breaks=seq(0,1,0.2))
Fig.2c
1、加载数据及数据处理
df2 <- read.csv("df_2.csv", encoding="UTF-8")
df2$Days <- factor(df2$Days, levels = c('76','90','106','120','141', "0"))
df2$group <- factor(df2$group, levels = c('Early successional','Mid-successional / No trend','Late successional'))
head(df2)
2、绘制基本箱线图
p2<-ggplot(data =df2, aes(x = Days, y = TotalAbund,fill=group)) +
geom_boxplot(width = 0.8)
3、按照group进行分面
p1+facet_wrap(~group,nrow=3)
4、添加散点
p1+geom_point(position='jitter',shape=16, alpha=.5)+
facet_wrap(~group,nrow=3)
5、主题设置及图例去除
p1+geom_point(position='jitter',shape=16, alpha=.5)+
theme_classic() +
facet_wrap(~group,nrow=3)+
labs(x = '', y = 'Relative abundance') +
scale_fill_manual(values = col)+
scale_y_continuous(expand = c(0,0))+
theme(legend.position = 'none',
strip.background = element_blank())+
geom_hline(aes(yintercept=0))+
theme(plot.title = element_text(size = 20,hjust = 0.5, face='bold')) +
theme(axis.title.x = element_text(size = 10,hjust = 0.5, face='bold')) +
theme(axis.title.y = element_text(size = 10,hjust = 0.5, face='bold')) +
theme(axis.text.x = element_text(angle = 0, hjust = 0.95, vjust=0.4,size=10, face='bold',color='black'))+
theme(axis.text.y = element_text(size=10, face='bold',color='black'))
参考:
https://github.com/hyunkim90/spatiotemporal_tracking_rice_endophytic_communities
代码及数据获取:后台回复'2022-8-10'获取!!!
我就知道你“在看”