||
文章:Seasonal cycling in the gut microbiome of the Hadza hunter-gatherers of Tanzania
杂志:Science
日期:2017
文章的图非常漂亮,如图1所示
左图尝试用ggplot2整理画图,基本实现图的效果,代码如下:
library("ggplot2")
data=read.table("pcoa_draw.csv",header=T)
gg<-merge(data,aggregate(cbind(mean.x=pcoa1,mean.y=pcoa2)~group,data,mean),by="group")
col <- c('light green','purple',"light purple","light blue","dark green")
p<-ggplot(gg, aes(x=pcoa1,y=pcoa2,fill=factor(gg$group)))
+ geom_point(size=2,aes(shape=factor(gg$group),color=factor(gg$group)))
+ stat_ellipse(aes(fill=factor(gg$group)),geom="polygon",level=0.75,alpha=0.2)
+ stat_ellipse(linetype=2,level=0.80,aes(color=factor(gg$group)))
+ scale_fill_manual(values=col)
+ scale_color_manual(values=col)
+ coord_fixed()
pcoa_draw.csv中的数据是显示样本pcoa1和pcoa2上的坐标,如下所示:
pcoa1 pcoa2 group
-0.090529581 -0.088593906 G1
-0.073695249 0.117958024 G2
-0.102392354 -0.067866335 G3
...
右图代码如下:
library(ggpubr)
ups<-read.delim("abundance.csv")
my_comparisons <- list(c("D1","D2"),c("D2","D3"),c("D1","D3")
col <- c('light green','purple',"light purple","light blue","dark green")
p<-ggboxplot(ups,x="phase",y="value",fill=factor(ups$phase))
+stat_compare_means(comparisons = my_comparisons,method="t.test")
+ scale_fill_manual(values=col)
+theme(legend.position="bottom",legend.title=element_blank())
大致效果虽实现,不过对于图的尺寸、比例需要根据数据情况继续调整。
另外右图横坐标感觉设置不止3个,猜测是作者为了图的美观性,特意在绘图时做了设计。
Archiver|手机版|科学网 ( 京ICP备07017567号-12 )
GMT+8, 2024-12-19 01:08
Powered by ScienceNet.cn
Copyright © 2007- 中国科学报社