前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >跟着Nature Communications学作图:R语言ggtern包画三元相图(Ternary plots )

跟着Nature Communications学作图:R语言ggtern包画三元相图(Ternary plots )

作者头像
用户7010445
发布2023-01-06 18:37:41
7580
发布2023-01-06 18:37:41
举报

论文

A highly conserved core bacterial microbiota with nitrogen-fixation capacity inhabits the xylem sap in maize plants

https://www.nature.com/articles/s41467-022-31113-w

本地pdf s41467-022-31113-w.pdf

数据代码链接

https://github.com/PlantNutrition/Liyu

今天的推文我们重复一下论文中的Figure2f

image.png

这个图怎们看,然后表达的是什么含义,我暂时还想不明白,论文中给的图注是

Ternary plots of OTUs in xylem sap across three fertilisation treatments. Size of each point represents relative abundance of OTU. Position is determined by the contribution of three fertilisation treatments to the total relative abundance, proximity to that vertex indicates enrichment of that OTU in that fertilisation treatment. Colours of circles correspond to different genera. Grey circles indicate OTUs with no significant differences in abundance.

作图数据部分截图

image.png

ggtern 这个R包是我第一次使用,首先需要安装,运行代码install.packages("ggtern")

读取数据集

代码语言:javascript
复制
plot_data <- read.table("data/20220612/Tern_data.txt", 
                       header=T, 
                       row.names= 1, 
                       sep="\t", 
                       comment.char = "")

作图代码

代码语言:javascript
复制
library(ggtern)
p <- ggtern(data=plot_data, aes(x=CK, y=NPK, z=NPKM)) + 
  geom_mask() + 
  geom_point(aes(size=size, color=Genus),alpha=0.8) +
  scale_size(range = c(0, 10)) +
  scale_color_manual(values  = c('#E31A1C','#228B22','#1F78B4', '#FDB462', '#8B658B',  '#4876FF', '#00BFFF', '#EE82EE','#8B8682','#CDC9C9'), limits = c('Klebsiella','Pseudomonas','Enterobacteriaceae_unclassified','Rosenbergiella','Oxalobacteraceae_unclassified','Sphingobacterium','Lactococcus','Erwinia','Others','NotSig')) +
  guides(size="none") +theme_bw() +
  theme(axis.text=element_blank(), axis.ticks=element_blank())
p

论文中的代码出图

image.png

调整图例的位置,可以用ggplot2中调整图例的方法

代码语言:javascript
复制
p+
  theme(legend.position = "bottom")+
  guides(color=guide_legend(nrow = 3,
                            override.aes = list(size = 5),
                            title.position = "top"))

image.png

试了一下和其他ggplot2的图进行组合,patchwork没有成功,找找有没有其他办法可以实现组合图

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2022-06-12,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 小明的数据分析笔记本 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 论文
  • 数据代码链接
  • 作图数据部分截图
  • 读取数据集
  • 作图代码
相关产品与服务
图数据库 KonisGraph
图数据库 KonisGraph(TencentDB for KonisGraph)是一种云端图数据库服务,基于腾讯在海量图数据上的实践经验,提供一站式海量图数据存储、管理、实时查询、计算、可视化分析能力;KonisGraph 支持属性图模型和 TinkerPop Gremlin 查询语言,能够帮助用户快速完成对图数据的建模、查询和可视化分析。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档