跟著Nature學(xué)作圖:R語言ggplot2箱線圖/散點(diǎn)圖完整示例

論文

Graph pangenome captures missing heritability and empowers tomato breeding

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

沒有找到論文里的作圖的代碼,但是找到了部分做圖數(shù)據(jù),我們可以用論文中提供的原始數(shù)據(jù)模仿出論文中的圖

今天的推文重復(fù)一下論文中的 Figure4d Figure4e 散點(diǎn)圖和箱線圖

image.png

箱線圖示例數(shù)據(jù)集

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

散點(diǎn)圖作圖代碼

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

示例數(shù)據(jù)和代碼可以自己到論文中獲取,或者給本篇推文點(diǎn)贊,點(diǎn)擊在看,然后留言獲取

歡迎大家關(guān)注我的公眾號

小明的數(shù)據(jù)分析筆記本

小明的數(shù)據(jù)分析筆記本 公眾號 主要分享:1、R語言和python做數(shù)據(jù)分析和數(shù)據(jù)可視化的簡單小例子;2、園藝植物相關(guān)轉(zhuǎn)錄組學(xué)、基因組學(xué)、群體遺傳學(xué)文獻(xiàn)閱讀筆記;3、生物信息學(xué)入門學(xué)習(xí)資料及自己的學(xué)習(xí)筆記!

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容