肖斌
Seasonal cycling in the gut microbiome of the Hadza图1的实现
2018-8-24 09:15
阅读:3067

文章: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个,猜测是作者为了图的美观性,特意在绘图时做了设计。

转载本文请联系原作者获取授权,同时请注明本文来自肖斌科学网博客。

链接地址:https://wap.sciencenet.cn/blog-306699-1130860.html?mobile=1

收藏

分享到:

当前推荐数:0
推荐到博客首页
网友评论0 条评论
确定删除指定的回复吗?
确定删除本博文吗?