跟着Nature学作图:R语言ggplot2箱线图/散点图完整示例

论文

Graph pangenome captures missing heritability and empowers tomato breeding

https://www.nature.com/articles/s41586-022-04808-9#MOESM8

没有找到论文里的作图的代码,但是找到了部分做图数据,我们可以用论文中提供的原始数据模仿出论文中的图

今天的推文重复一下论文中的 Figure4d Figure4e 散点图和箱线图

image.png

箱线图示例数据集

image.png

作图代码

library(readxl)
dat01<-read_excel("data/20220711/41586_2022_4808_MOESM8_ESM.xlsx",
                  sheet = "Fig4e",
                  skip = 1)
dat01

library(ggplot2)

dat01$Type<-factor(dat01$Type,
                   levels = c("SNP","InDel","SV","SV array"))

ggplot(data=dat01,aes(x=Type,y=Accuracy))+
  
  geom_line(aes(group=Metabolic),
            color="grey")+
  geom_boxplot(aes(color=Type),
               fill="transparent")+
  geom_point(aes(color=Type))+
  theme_bw()+
  theme(panel.grid = element_blank(),
        legend.position = "none")+
  scale_color_manual(values = c("#3288bd","#66c2a5",
                                "#f46d43","#f1226e"))+
  labs(x=NULL,y="Prediction accuracy") -> p1

p1

image.png

散点图作图代码

dat02<-read_excel("data/20220711/41586_2022_4808_MOESM8_ESM.xlsx",
                  sheet = "Fig4d",
                  skip = 1)
dat02

library(paletteer)
library(latex2exp)

ggplot(data=dat02,aes(x=accuracy_snp,y=accuracy_sv))+
  geom_point(aes(color=h2_snp))+
  scale_x_continuous(limits = c(0,0.5),
                     expand = expansion(mult = c(0,0)))+
  scale_y_continuous(limits = c(0,0.5),
                     expand = expansion(mult = c(0,0)))+
  geom_abline(slope = 1,intercept = 0,lty="dashed")+
  theme_bw()+
  theme(panel.grid = element_blank(),
        panel.border = element_blank(),
        axis.line = element_line(),
        legend.position = c(0.8,0.3))+
  scale_color_paletteer_c(palette="grDevices::heat.colors",
                          direction = -1,
                          breaks=c(0.01,0.5,0.99),
                          labels=c(0,"0.50","1.00"),
                          name=TeX(r"(\textit{h}${^2}$)"))+
  labs(x="Accuracy of SNP",y="Accuracy of SV") -> p2

p2
image.png

拼图

library(patchwork)

p2+p1
image.png

示例数据和代码可以自己到论文中获取,或者给本篇推文点赞,点击在看,然后留言获取

欢迎大家关注我的公众号

小明的数据分析笔记本

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

你可能感兴趣的:(跟着Nature学作图:R语言ggplot2箱线图/散点图完整示例)