Graph pangenome captures missing heritability and empowers tomato breeding
https://www.nature.com/articles/s41586-022-04808-9#MOESM8
没有找到论文里的作图的代码,但是找到了部分组图数据,我们可以用论文中提供的原始数据模仿出论文中的图
今天的推文重复一下论文中的Figure2c 频率分布直方图
image.png
image.png
作图数据用到的是R2那一列
library(readxl)
dat.fig2c<-read_excel("data/20220711/41586_2022_4808_MOESM6_ESM.xlsx",
sheet = "Fig2c",
skip = 1)
head(dat.fig2c)
这里第一行数据没有用,我们可以选择手动删除,或者设置读取数据时不读取第一行
library(ggplot2)
library(latex2exp)
ggplot(data=dat.fig2c,aes(x=R2))+
geom_histogram(aes(y=after_stat(count / sum(count)),
fill=Type),
bins = 150,
alpha=0.3)+
scale_fill_manual(values = c("InDel-SV"="#a3cd5b",
"SNP-SV"="#8ea0cc"),
labels=c("InDel-SV"="InDel versus SV",
"SNP-SV"="SNP versus SV"))+
theme_bw()+
theme(panel.border = element_blank(),
panel.grid = element_blank(),
axis.line = element_line(),
legend.position = c(0.1,0.9),
legend.direction = "horizontal",
legend.background = element_rect(fill="transparent"),
legend.title = element_blank(),
legend.justification = c(0,1))+
scale_x_continuous(limits = c(0,1),
expand = expansion(mult = c(0,0)))+
scale_y_continuous(limits = c(0,0.025),
expand = expansion(mult = c(0,0)),
breaks = seq(0,0.025,0.005),
labels = function(x){sprintf("%0.1f",x*100)})+
labs(x=TeX(r"(\textit{R}$^2$)"),
y="Frequency (%)")+
geom_vline(xintercept = 0.7,lty="dashed") -> p1
p1
image.png
这里我个人认为把直方图的边框加上然后颜色深一些可能会好看一点
ggplot(data=dat.fig2c,aes(x=R2))+
geom_histogram(aes(y=after_stat(count / sum(count)),
fill=Type),
bins = 150,
alpha=1,
color="black")+
scale_fill_manual(values = c("InDel-SV"="#a3cd5b",
"SNP-SV"="#8ea0cc"),
labels=c("InDel-SV"="InDel versus SV",
"SNP-SV"="SNP versus SV"))+
theme_bw()+
theme(panel.border = element_blank(),
panel.grid = element_blank(),
axis.line = element_line(),
legend.position = c(0.1,0.9),
legend.direction = "horizontal",
legend.background = element_rect(fill="transparent"),
legend.title = element_blank(),
legend.justification = c(0,1))+
scale_x_continuous(limits = c(0,1),
expand = expansion(mult = c(0,0)))+
scale_y_continuous(limits = c(0,0.025),
expand = expansion(mult = c(0,0)),
breaks = seq(0,0.025,0.005),
labels = function(x){sprintf("%0.1f",x*100)})+
labs(x=TeX(r"(\textit{R}$^2$)"),
y="Frequency (%)")+
geom_vline(xintercept = 0.7,lty="dashed") -> p2
p2
image.png
library(patchwork)
p1+p2
image.png
这里新学到的知识点:使用latex2exp
这个R包的TeX()
函数来添加文本比expression()
函数好用
比如这里设置 横坐标轴标题的斜体和上标的代码x=TeX(r"(\textit{R}
示例数据和代码可以自己到论文中获取
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有