美文网首页
散点图+边缘箱线图

散点图+边缘箱线图

作者: 北欧森林 | 来源:发表于2021-01-18 09:48 被阅读0次

本帖拟复现的是2019年1月发表在Nature Communication上面的一篇题为“Fecal pollution can explain antibiotic resistance gene abundances in anthropogenically impacted environments”中的一幅。具体的研究内容看不太懂(也没时间看),但是里面的图确实很漂亮。更为重要的是研究者在GitHub上提供了整篇文章完整的绘图代码(R语言)和数据(具体见:https://github.com/karkman/crAssphage_project),真是学习R语言作图的极佳材料。

本帖重现文中第一幅图。

library(tidyverse)
library(vegan)
library(grid)
library(gridExtra)

cols <- c("#E69F00", "#56B4E9", "#009E73", "#F0E442", "#0072B2", "#D55E00", "#CC79A7")

HMP <- read.table("data/HMP.txt")
crass_impact <- read.table("data/crass_impact.txt")
MG_RAST <- read.table("data/MG-RAST.txt")
crass_wwtp <- read.table("data/crass_wwtp.txt")
res_risk <- read.table("data/res_risk.txt")
par(fig=c(0,0.45,0,0.8) )
plot(log10(rel_res)~log10(rel_crAss), data=HMP, bg=cols[as.factor(HMP$country)], pch=21,
     ylab = "Normalized ARG abundance (log10)", 
     xlab = "Normalized crAssphage abundance (log10)", cex=2, ylim=c(2.5, 4.5))

par(fig=c(0,0.45,0.5,1), new=TRUE)
boxplot(log10(rel_crAss) ~ country, data=HMP, horizontal=TRUE, col=cols, axes=F,
        xlab = NULL,ylab = NULL)  #xlab,ylab坐标信息不显示
axis(2, at=1:3, labels=c("China", "Europe", "US"), las=1) #2为y坐标;las1为字体横向,0为纵向;
title("a", adj = 0, line = 0)

par(fig=c(0.45,0.9,0,0.8), new=TRUE)
tmp <- subset(HMP, rel_int>0)
plot(log10(rel_res) ~ log10(rel_int), data=tmp, bg=cols[as.factor(tmp$country)], pch=21,
     ylab = "", xlab="Normalized intI1 abundance (log10)", cex=2, ylim=c(2.5, 4.5))

par(fig=c(0.45,0.9,0.5,1), new=TRUE)
boxplot(log10(rel_int) ~ country, data=tmp, horizontal=TRUE, col=cols, axes=F,
        xlab = NULL,ylab = NULL)
axis(2, at=1:3, labels=c("China", "Europe", "US"), las=1)
title("b", adj = 0, line = 0)

par(fig=c(0.8,1,0,0.8),new=TRUE)
boxplot(log10(rel_res)~country, data=HMP, col=cols, axes=F,
        xlab = NULL, ylab = NULL)
axis(1, at=1:3, labels=c("China", "Europe", "US"), las=3)

结果如图:


Fig1.png

另外两幅图的关键代码如下:

ggplot(crass_impact, aes(x=rel_crAss, y=rel_res, color=country)) + 
  geom_point(aes(shape=crAss_detection), size=5) + 
  scale_x_log10() + 
  scale_y_log10() + 
  geom_smooth(method="lm") + 
  theme_classic() +
  labs(y = "Normalized ARG abundance", x="Normalized crAssphage abundance", 
       color="Study", shape="crAssphage detection") + scale_colour_manual(values=cols)
Fig2.png
p1 <- ggplot(res_risk,aes(y=ResRisk,x=log10(rel_res),color=Environment)) + 
  geom_point(size=5) + 
  labs(y = "Resistance risk", x="Normalized ARG abundance") +
  theme_classic() 
p2 <- ggplot(res_risk,aes(y=ResRisk,x=log10(rel_crAss),color=Environment)) + 
  geom_point(size=5) + 
  labs(y = "Resistance risk", x="Normalized crAssphage abundance") +
  theme_classic() 
grid_arrange_shared_legend(p1,p2, ncol=2)
Fig3

原文里主图4幅,附图7幅,也顺便欣赏一下其它几幅吧(图做得真的很漂亮啊!)


unnamed-chunk-18-1.jpeg unnamed-chunk-21-1.jpeg unnamed-chunk-23-1.jpeg

相关文章

网友评论

      本文标题:散点图+边缘箱线图

      本文链接:https://www.haomeiwen.com/subject/wtngaktx.html