# 跟着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

## 首先是图a频率分布直方图

library(readxl)
sheet = "Panel a")
dat

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

ggplot(data=dat,aes(x=Var1))+
geom_histogram(bins = 25,
color="white",
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_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')),
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

|
6月前
|

R语言绘图教程丨Nature论文都在用的多组比较箱线图，自动计算显著性并标注，附带误差线
R语言绘图教程丨Nature论文都在用的多组比较箱线图，自动计算显著性并标注，附带误差线
330 0
|
6月前
R语言笔记丨散点图怎么画？
R语言笔记丨散点图怎么画？
179 0
|
8月前
R语言绘制组间比较散点图并自动添加P值信息

115 3
|
9月前
|

103 0
|
9月前
|

171 0
|
9月前
|

92 0
|