论文
Graph pangenome captures missing heritability and empowers tomato breeding
https://www.nature.com/articles/s41586-022-04808-9#MOESM8
没有找到论文里的作图的代码,但是找到了部门组图数据,我们可以用论文中提供的原始数据模拟出论文中的图
本日的推文重复一下论文中的Figure1c
本日紧张的知识点是多个图例的时间怎样分开放,现在想到的办法是利用ggpubr这个R包把图例单独挑出来,然后利用annotation_custom()函数再把图例加回去。不知道有没有更方便的办法
部门示例数据截图
读取数据
dat01<-read.delim("data/20220719/Fig1c.txt", sep = "\t", header = TRUE, check.names = FALSE)dat01转换成作图数据
library(tidyverse)library(stringr)#str_pad('1',2,side = "left",pad = "0")dat01 %>% filter(`Reference genome`!="p value") %>% mutate(variants=rep(rep(c("SNP","InDel","SV"),each=2),times=3)) %>% pivot_longer(-c(`Reference genome`,variants)) %>% mutate(name=as.numeric(str_replace(name,'x',''))) %>% group_by(`Reference genome`,variants,name) %>% summarise(mean_value=mean(value)) %>% ungroup() -> new.data最根本的图
library(ggplot2)ggplot(data=new.data,aes(x=name,y=mean_value))+ geom_line(aes(color=variants,lty=`Reference genome`))+ geom_point(aes(color=variants))细节调解
ggplot(data=new.data,aes(x=name,y=mean_value))+ geom_line(aes(color=variants,lty=`Reference genome`))+ geom_point(aes(color=variants),size=5)+ scale_color_manual(values = c("InDel"="#a4d6c1", "SNP"="#b6e0f0", "SV"="#ea6743"))+ labs(y=TeX(r"(\textit{F}${_1}$ score)"), x="Sequencing depth")+ theme_classic()+ scale_y_continuous(limits = c(0.4,1), breaks = c(0.4,0.6,0.8,1.0), expand = expansion(mult = c(0.1,0)))
图例位置
library(ggpubr)ggplot(data=new.data,aes(x=name,y=mean_value))+ geom_line(aes(color=variants,lty=`Reference genome`), show.legend = FALSE)+ geom_point(aes(color=variants),size=5)+ scale_color_manual(values = c("InDel"="#a4d6c1", "SNP"="#b6e0f0", "SV"="#ea6743"), name="")+ labs(y=TeX(r"(\textit{F}${_1}$ score)"), x="Sequencing depth")+ theme_classic()+ scale_y_continuous(limits = c(0.4,1), breaks = c(0.4,0.6,0.8,1.0), expand = expansion(mult = c(0.1,0))) -> p1as_ggplot(get_legend(p1)) -> legend.01ggplot(data=new.data,aes(x=name,y=mean_value))+ geom_line(aes(color=variants,lty=`Reference genome`))+ geom_point(aes(color=variants),size=5)+ scale_color_manual(values = c("InDel"="#a4d6c1", "SNP"="#b6e0f0", "SV"="#ea6743"), name="")+ labs(y=TeX(r"(\textit{F}${_1}$ score)"), x="Sequencing depth")+ theme_classic()+ scale_y_continuous(limits = c(0.4,1), breaks = c(0.4,0.6,0.8,1.0), expand = expansion(mult = c(0.1,0)))+ guides(color="none")+ theme(legend.position = "top", legend.title = element_blank()) -> p2as_ggplot(get_legend(p2)) -> legend.02ggplot(data=new.data,aes(x=name,y=mean_value))+ geom_line(aes(color=variants,lty=`Reference genome`))+ geom_point(aes(color=variants),size=5)+ scale_color_manual(values = c("InDel"="#a4d6c1", "SNP"="#b6e0f0", "SV"="#ea6743"))+ labs(y=TeX(r"(\textit{F}${_1}$ score)"), x="Sequencing depth")+ theme_classic()+ scale_y_continuous(limits = c(0.4,1), breaks = c(0.4,0.6,0.8,1.0), expand = expansion(mult = c(0.1,0))) -> ppp + theme(plot.margin = unit(c(1,0.1,0.1,0.1),'cm'), legend.position = "none")+ coord_cartesian(clip = "off")+ annotation_custom(grob = ggplotGrob(legend.01), xmin = 22,xmax = 22, ymin=0.5,ymax = 0.5)+ annotation_custom(grob = ggplotGrob(legend.02), xmin = 15,xmax = 15, ymin=1.05,ymax = 1.05)最闭幕果
封面图
library(patchwork)pdf(file = "abc.pdf", width = 9.4,height = 4)pp + ppdev.off()
示例数据和代码可以本身到论文中获取,大概给本篇推文点赞,点击在看,然后留言获取
欢迎各人关注我的公众号
小明的数据分析笔记本
小明的数据分析笔记本 公众号 紧张分享:1、R语言和python做数据分析和数据可视化的简朴小例子;2、园艺植物相干转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及本身的学习笔记!
|