xbinbzy的个人博客分享 http://blog.sciencenet.cn/u/xbinbzy

博文

Seasonal cycling in the gut microbiome of the Hadza图1的实现

已有 2975 次阅读 2018-8-24 09:15 |个人分类:科研文章|系统分类:科研笔记

文章: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://blog.sciencenet.cn/blog-306699-1130860.html

上一篇:有关生命体的科学纪录片
下一篇:基于ggplot2的散点图
收藏 IP: 210.21.228.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-3-29 19:29

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部