今天要模仿的图片来自于论文 Core gut microbial communities are maintained by beneficial interactions and strain variability in fish。期刊是 Nature microbiology
image.png
今天重复的图片是Figure4中的小a,在一幅图的右上角放一幅图
image.png
之前的推文介绍过相关的内容
超链接
首先是频率分布直方图
第一步是准备数据
image.png
频率分布直方图之前的推文有过详细的介绍,点击下方蓝字直达,这里的代码就不再过多介绍
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)
image.png
接下来是箱线图
准备数据
image.png
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")
image.png
最后是将箱线图放到直方图的右上角
g1<-ggplotGrob(p2)
p1+annotation_custom(g1,xmin=6,xmax = 8,ymin = 8,ymax=15)
image.png
需要示例数据的先给这篇推文点赞,直接在文末留言就可以了。
欢迎大家关注我的公众号
小明的数据分析笔记本