跟著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ù)一下論文中的 Extended Data Fig7a

image.png

部分示例數(shù)據(jù)截圖

image.png

將數(shù)據(jù)整理成作圖需要的格式

library(tidyverse)
table(dat01$type)

dat01 %>% 
  filter(type=="cis_gwas") -> dat01.gwas

dim(dat01.gwas)

dat01 %>% 
  filter(type == "cis_local") -> dat01.local

dim(dat01.local)

left_join(dat01.gwas,dat01.local,by="ID") -> dat

作圖代碼

這里沒有搞清楚他用來映射顏色的數(shù)據(jù)是什么,這里我就直接用x軸的數(shù)據(jù)映射顏色了

library(ggplot2)
library(paletteer)
library(latex2exp)

help(package="latex2exp")

ggplot(data=dat,aes(x=h2.x,y=h2.y))+
  geom_point(aes(color=h2.x))+
  scale_color_paletteer_c(palette="ggthemes::Blue-Green Sequential",
                          direction = -1,
                          name="n neighbours")+
  theme_bw()+
  theme(panel.grid = element_blank(),
        legend.position = c(0.8,0.2))+
  geom_abline(slope = 1,intercept = 0,lty="dashed")+
  scale_x_continuous(limits = c(0,1),
                     breaks = seq(0,1,by=0.25))+
  scale_y_continuous(limits = c(0,1),
                     breaks = seq(0,1,by=0.25))+
  labs(x=TeX(r"(\textit{h}$^2$ {(\textit{cis})} { GWAS})"),
       y=TeX(r"(\textit{h}$^2$ {(\textit{cis})} { local})"))

image.png

今天的推文沒啥新知識(shí)點(diǎn),熟悉下ggplot2的基本語法,熟悉下latex2exp這個(gè)R包用來添加文本的語法

拼圖

library(patchwork)
p+
  scale_color_paletteer_c("ggthemes::Red-Green Diverging",
                          direction = -1) +
  p
image.png

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

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

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

小明的數(shù)據(jù)分析筆記本 公眾號(hào) 主要分享: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)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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

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