跟着Nature学作图:R语言ggplot2散点图和添加辅助线完备示例

分享
程序员 2024-9-15 18:23:21 53 0 来自 中国
论文

Graph pangenome captures missing heritability and empowers tomato breeding
https://www.nature.com/articles/s41586-022-04808-9#MOESM8
没有找到论文里的作图的代码,但是找到了部门组图数据,我们可以用论文中提供的原始数据模仿出论文中的图
本日的推文重复一下论文中的 Extended Data Fig7a
部门示例数据截图

将数据整理成作图须要的格式

library(tidyverse)table(dat01$type)dat01 %>%   filter(type=="cis_gwas") -> dat01.gwasdim(dat01.gwas)dat01 %>%   filter(type == "cis_local") -> dat01.localdim(dat01.local)left_join(dat01.gwas,dat01.local,by="ID") -> dat作图代码

这里没有搞清晰他用来映射颜色的数据是什么,这里我就直接用x轴的数据映射颜色了
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})")) 3.png 本日的推文没啥新知识点,认识下ggplot2的根本语法,认识下latex2exp这个R包用来添加文本的语法
拼图

library(patchwork)p+  scale_color_paletteer_c("ggthemes::Red-Green Diverging",                          direction = -1) +  p 4.png
示例数据和代码可以本身到论文中获取,大概给本篇推文点赞,点击在看,然后留言获取
欢迎各人关注我的公众号
小明的数据分析条记本
小明的数据分析条记本 公众号 紧张分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物干系转录组学、基因组学、群体遗传学文献阅读条记;3、生物信息学入门学习资料及本身的学习条记!
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-10-19 04:24, Processed in 0.148824 second(s), 35 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表