美文网首页plot基因组数据绘图ggplot2绘图
跟着Nature Microbiology学作图:R语言ggpl

跟着Nature Microbiology学作图:R语言ggpl

作者: 小明的数据分析笔记本 | 来源:发表于2021-11-28 22:03 被阅读0次

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

    论文

    Protective role of the Arabidopsis leaf microbiota against a bacterial pathogen

    image.png

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

    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")
    

    添加拟合曲线

    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")
    

    计算拟合方程的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")
    
    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")
    
    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")
    
    
    image.png

    如果需要推文的示例数据和代码可以直接给推文打赏1元,如果打赏了没有收到我的回复,可以加我的微信mingyan24催我

    欢迎大家关注我的公众号

    小明的数据分析笔记本

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

    相关文章

      网友评论

        本文标题:跟着Nature Microbiology学作图:R语言ggpl

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