美文网首页收藏
跟着Nature Plants学作图:R语言ggplot2画分组

跟着Nature Plants学作图:R语言ggplot2画分组

作者: 小明的数据分析笔记本 | 来源:发表于2022-05-18 18:48 被阅读0次

    论文

    The flying spider-monkey tree fern genome provides insights into fern evolution and arborescence

    https://www.nature.com/articles/s41477-022-01146-6#Sec44

    数据下载链接

    https://doi.org/10.6084/m9.figshare.19125641

    今天的推文重复一下论文中的Figure1d中左下角的小图

    image.png

    论文中提供的原始数据集如下

    image.png

    需要将其整理成3个单独的数据集

    image.png

    首先是做数据整理的代码

    library(readxl)
    library(ggplot2)
    library(tidyverse)
    
    dat01<-read_excel("data/20220518/dat01.xlsx")
    dat01
    
    dat01 %>% 
      mutate(x=8:2,
             mean_value=`Duplication Per`,
             lower95=`Duplication Per`,
             upper95=`Duplication Per`,
             group="Experimental") %>% 
      select(x,mean_value,lower95,upper95,group)-> dat01
    
    dat02<-read_excel("data/20220518/dat02.xlsx")
    head(dat02)
    dat02 %>% 
      group_by(MRCA) %>% 
      summarise(mean_value = mean(`Duplication Per`),
                lower95 = Rmisc::CI(`Duplication Per`)[3],
                upper95 = Rmisc::CI(`Duplication Per`)[1]) %>% 
      mutate(x=8:2,
             group="Null simulation") %>% 
      select(x,mean_value,lower95,upper95,group) -> dat02
    
    dat03<-read_excel("data/20220518/dat03.xlsx")
    head(dat03)
    dat03 %>% 
      group_by(MRCA) %>% 
      summarise(mean_value = mean(`Duplication Per`),
                lower95 = Rmisc::CI(`Duplication Per`)[3],
                upper95 = Rmisc::CI(`Duplication Per`)[1]) %>% 
      mutate(x=8:2,
             group="Positive simulation") %>% 
      select(x,mean_value,lower95,upper95,group) -> dat03
    
    dat<-bind_rows(dat01,dat02,dat03)
    dat %>% 
      mutate(group=fct_rev(group)) -> dat
    

    作图代码

    ggplot(data = dat,aes(x=x,y=mean_value))+
      geom_line(aes(color=group),size=1.5)+
      geom_ribbon(aes(ymin=lower95-1,ymax=upper95+1,
                      fill=group),
                  alpha=0.5,
                  show.legend = FALSE)+
      theme_minimal()+
      theme(panel.grid = element_blank(),
            axis.line = element_line(),
            axis.ticks = element_line(),
            legend.title = element_blank())+
      scale_x_continuous(breaks = 2:8,
                         labels = paste0("N",8:2))+
      scale_y_continuous(breaks = c(0,25))+
      labs(x="Subtree node",y="Percent subtree")
    

    最终结果

    image.png

    这里最终的结果和论文中的图还是有些差异的,因为我没有看到论文中用的是置信区间作为数据范围还是其他,我这里选择的是置信区间,然后对数值进行了加减1

    示例数据可以到论文中去下载,代码可以在推文中复制

    欢迎大家关注我的公众号

    小明的数据分析笔记本

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

    相关文章

      网友评论

        本文标题:跟着Nature Plants学作图:R语言ggplot2画分组

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