跟着Nature學作圖:R語言ggplot2頻率分佈直方圖和散點圖添加誤差線

論文

A saturated map of common genetic variants associated with human height

https://www.nature.com/articles/s41586-022-05275-y

s41586-022-05275-y.pdf

代碼沒有公開,但是作圖數據基本都公開了,爭取把每個圖都重複一遍

今天的推文重複論文中的extended Figure4 頻率分佈直方圖和散點圖添加誤差線

首先是圖a頻率分佈直方圖

library(readxl)
dat<-read_excel("extendFig4.xlsx",
                sheet = "Panel a")
dat

colnames(dat)<-"Var1"
library(ggplot2)
library(ggh4x)


ggplot(data=dat,aes(x=Var1))+
  geom_histogram(bins = 25,
                 color="white",
                 fill="#aadbe9")+
  scale_x_continuous(limits = c(0.5,3),
                     breaks = seq(0.5,3,by=0.5))+
  scale_y_continuous(limits = c(0,300),
                     breaks = seq(0,300,50))+
  geom_vline(xintercept = 0.75,lty="dashed",color="#aadbe9")+
  geom_vline(xintercept = 2.25,lty="dashed",color="#aadbe9")+
  geom_segment(aes(x=2.5,xend=2.5,y=50,yend=0),
               arrow = arrow(),
               color="red")+
  annotate(geom = "text",x=2.5,y=50,label="Observed",
           vjust=-1)+
  geom_segment(aes(x=0.75,xend=2.25,y=250,yend=250),
               arrow = arrow(ends = "both",
                             angle=20,
                             length = unit(3,'mm')),
               color="#aadbe9")+
  annotate(geom = "text",x=1.5,y=250,
           label="Null distribution (1,000 draws)",
           vjust=-1)+
  theme_classic()+
  guides(x=guide_axis_truncated(trunc_lower = 0.5,
                                trunc_upper = 3),
         y=guide_axis_truncated(trunc_lower = 0,
                                trunc_upper = 300))+
  labs(y="Frequency",
       x="Enrichment folde of OMIM genes\nnear GWS SNPs with a density > 1")

第二個圖b

datb<-read_excel("extendFig4.xlsx",
                sheet = "Panel b")
datb
ggplot(data=datb,aes(x=`Minimum Signal Density`,
                     y=`Enrichment statistic`))+
  geom_point()+
  geom_errorbar(aes(ymin=`Enrichment statistic`-`Standard Error of Enrichment Statistic`,
                    ymax=`Enrichment statistic`+`Standard Error of Enrichment Statistic`),
                width=0.4)+
  scale_x_continuous(limits = c(0.5,10.5),
                     breaks = 1:10)+
  scale_y_continuous(limits = c(0,9),
                     breaks = 0:8)+
  theme_classic()+
  guides(x=guide_axis_truncated(trunc_lower = 1,
                                trunc_upper = 10),
         y=guide_axis_truncated(trunc_lower = 0,
                                trunc_upper = 8))+
  labs(x="Minimum Signal Density",
       y="Enrichment-fold of OMIM genes\nnear GWS SNPs")

最後是拼圖

library(patchwork)
p1+p2

示例數據和代碼可以給公衆號推文點贊,點擊在看,最後留言獲取

歡迎大家關注我的公衆號

小明的數據分析筆記本

小明的數據分析筆記本 公衆號 主要分享:1、R語言和python做數據分析和數據可視化的簡單小例子;2、園藝植物相關轉錄組學、基因組學、羣體遺傳學文獻閱讀筆記;3、生物信息學入門學習資料及自己的學習筆記!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章