跟着Nature Microbiology学作图:R语言ggplot2做散点图添加拟合曲线和p值

本地文件 s41564-021-00997-7.pdf

论文

Protective role of the Arabidopsis leaf microbiota against a bacterial pathogen

703dc5f533f45fed5afaa5366038c373.png
image.png

今天的推文来重复一下论文中的figure3c 散点图添加拟合曲线

0e5084a5697f6879fa72836a4a1ff770.png
image.png

读取数据集

library(readxl)
df<-read_excel("41564_2021_997_MOESM10_ESM.xlsx")
head(df)
colnames(df)

最基本的散点图

library(ggplot2)
ggplot(data=df,aes(x=`mean Protection Score [a.u.]`,
                   y=`mean Colonization [log10(CFU/mg)]`))+
  geom_point(aes(color=Phylum))+
  ggsave(filename = "fig3c.pdf",
         width = 6,
         height = 4,
         family="serif")
e93b9f954ff900ec764047d28098192f.png

添加拟合曲线

ggplot(data=df,aes(x=`mean Protection Score [a.u.]`,
                   y=`mean Colonization [log10(CFU/mg)]`))+
  geom_point(aes(color=Phylum))+
  geom_smooth(method = "lm",
              formula = "y~x",
              se=F,
              color="grey")+
  ggsave(filename = "fig3c.pdf",
         width = 6,
         height = 4,
         family="serif")
7e35414f554935c4fd3e2f6fbf2b22ea.png

计算拟合方程的R和P值

df.lm<-lm(`mean Colonization [log10(CFU/mg)]`~
     `mean Protection Score [a.u.]`,
   data=df)
summary(df.lm)

sqrt(0.242)

ggplot(data=df,aes(x=`mean Protection Score [a.u.]`,
                   y=`mean Colonization [log10(CFU/mg)]`))+
  geom_point(aes(color=Phylum))+
  geom_smooth(method = "lm",
              formula = "y~x",
              se=F,
              color="grey")+
  annotate(geom = "text",
           x=60,y=1.2,
           label=expression(italic(R)~"="~0.49~","~italic(P)~"="~5.4%*%10^-15),
           parse=T)+
  ggsave(filename = "fig3c.pdf",
         width = 6,
         height = 4,
         family="serif")
5f2f48142b1452a6cecc83980e690c64.png
image.png

添加虚线注释框

ggplot(data=df,aes(x=`mean Protection Score [a.u.]`,
                   y=`mean Colonization [log10(CFU/mg)]`))+
  geom_point(aes(color=Phylum))+
  geom_smooth(method = "lm",
              formula = "y~x",
              se=F,
              color="grey")+
  annotate(geom = "text",
           x=60,y=1.2,
           label=expression(italic(R)~"="~0.49~","~italic(P)~"="~5.4%*%10^-15),
           parse=T)+
  annotate(geom = "rect",
           xmin = 75,
           xmax = 100,
           ymin = 4.5,
           ymax = 7,
           alpha=0,
           color="black",
           lty="dashed")+
  ggsave(filename = "fig3c.pdf",
         width = 6,
         height = 4,
         family="serif")
d6b2db78dfbe0062e12a1c8ce7a27c2d.png
image.png

最后是调节主题美化

colors<-c("#96d796","#aed75b","#599943",
          "#499ef1","#f18282","#ffdf33")
ggplot(data=df,aes(x=`mean Protection Score [a.u.]`,
                   y=`mean Colonization [log10(CFU/mg)]`))+
  geom_point(aes(fill=Phylum,
                 color=Phylum),
             shape=21,
             key_glyph="rect")+
  geom_smooth(method = "lm",
              formula = "y~x",
              se=F,
              color="grey")+
  annotate(geom = "text",
           x=60,y=1.2,
           label=expression(italic(R)~"="~0.49~","~italic(P)~"="~5.4%*%10^-15),
           parse=T)+
  annotate(geom = "rect",
           xmin = 75,
           xmax = 100,
           ymin = 4.5,
           ymax = 7,
           alpha=0,
           color="black",
           lty="dashed")+
  theme_bw()+
  theme(panel.grid = element_blank(),
        legend.title = element_blank())+
  scale_fill_manual(values = colors)+
  scale_color_manual(values = colors)+
  ggsave(filename = "fig3c.pdf",
         width = 9.4,
         height = 4,
         family="serif")
5314755f93086fbcc9843fc597004b7f.png
image.png

小明的数据分析笔记本

小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!

  • 3
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值