今天要模仿的图片来自于论文 Core gut microbial communities are maintained by beneficial interactions and strain variability in fish。期刊是 Nature microbiology
今天重复的图片是Figure4中的小a,在一幅图的右上角放一幅图
第一步是准备数据
频率分布直方图之前的推文有过详细的介绍,点击下方蓝字直达,这里的代码就不再过多介绍
library(ggplot2)
df1<-read.csv("histogram_1.csv",header=T)
ggplot(df1,aes(A))+
geom_histogram(binwidth = 0.1,
color="white",fill="#4c72b0")+
theme(panel.background = element_blank(),
axis.line = element_line())+
labs(x="Average number of strains within a pool",
y="Number of pools of 8 microbes")+
ylim(0,14)
准备数据
df2<-read.csv("boxplot_1.csv",header=T)
df3<-reshape2::melt(df2)
head(df3)
df3$variable<-factor(df3$variable,
levels = c("Non_Core","Core"),
labels = c("Non-core","Core"))
ggplot(df3,aes(x=variable,y=value,group=variable))+
geom_boxplot(size=1,outlier.colour = "white")+
geom_dotplot(binaxis='y', stackdir='center',
binwidth = 0.1,
aes(fill=variable))+
theme_bw()+
theme(panel.grid = element_blank(),
plot.title = element_text(hjust=0.5),
legend.position = "none")+
scale_fill_manual(values = c("#4c72b0","#dd8452"))+
labs(x=NULL,y="Number of strains",
title = "Strain diversity for OTUs\nwith >3,000 reads")+
annotate("text",x=0.6,y=8,label="P=0.016")
g1<-ggplotGrob(p2)
p1+annotation_custom(g1,xmin=6,xmax = 8,ymin = 8,ymax=15)