论文
Pan-African genome demonstrates how population-specific genome graphs improve high-throughput sequencing data analysis
https://www.nature.com/articles/s41467-022-31724-3
当地pdf s41467-022-31724-3.pdf
论文中公布了大部门图的数据,但是没有公布对应的作图代码,没有关系,我们可以本身写代码试着模拟,本日的推文重复一下论文中的Figure 2A 带有条纹的分组柱形图
示例数据截图
这里实现条纹柱形图用到的是 ggpattern这个R包
参考链接
https://coolbutuseless.github.io/package/ggpattern/index.html
https://github.com/coolbutuseless/ggpattern
安装
remotes::install_github("coolbutuseless/ggpattern")由于是ggplot2的扩展包,除了把作图函数更换,别的的细节都可以用ggplot2的语法来调治
读取数据
library(readxl)dffig2a<-read_excel("data/20220806/41467_2022_31724_MOESM4_ESM.xlsx", sheet = "figure 2a")dffig2alibrary(tidyverse)dffig2a %>% pivot_longer(-'Super-population') -> new.dffig2a作图代码
library(ggplot2)cols<-c("#ffa657","#fd8011","#6cbe6c","#349734", "#eba0d5","#da7dbd","#63a0cb","#1f7ab4", "#d0d166","#bbbe21")ggplot(data = new.dffig2a,aes(x=`Super-population`,y=value))+ geom_bar_pattern(stat="identity", position = "dodge", aes(pattern=name, fill=name), pattern_density=0.01, fill=cols, color="black", show.legend = FALSE)+ scale_pattern_manual(values = c('Divergence'='stripe', 'Diversity'="none"))+ scale_y_continuous(expand = expansion(mult = c(0,0.1)), labels = scales::percent, limits = c(0,0.25/100), breaks = seq(0,0.25/100,by=0.05/100))+ labs(x=NULL,y=NULL)+ theme_classic()+ theme(axis.line.y = element_blank(), axis.ticks.y = element_blank(), panel.grid = element_line(linetype = "dashed"), panel.grid.major = element_line(), panel.grid.minor = element_blank()) -> p1p1ggplot()+ geom_rect_pattern(data=data.frame(x=1,xend=2,y=1,yend=2), aes(xmin=x,ymin=y,xmax=xend,ymax=yend), pattern_density=1, fill="white", color="black")+ geom_rect_pattern(data=data.frame(x=1,xend=2,y=2.5,yend=3.5), aes(xmin=x,ymin=y,xmax=xend,ymax=yend), pattern="none", pattern_density=1, fill="grey", color="black")+ theme_void()+ geom_text(data=data.frame(x=2,y=1.5), aes(x=x,y=y),label="Divergence", hjust=-0.1)+ geom_text(data=data.frame(x=2,y=3), aes(x=x,y=y),label="Diversity", hjust=-0.1)+ xlim(1,4) -> p2p1+ annotation_custom(grob = ggplotGrob(p2), xmin = 4,xmax = Inf, ymin = 0.2/100,ymax=0.25/100) -> p3p3library(patchwork)p3+p3示例数据可以在论文中去下载,代码直接在推文中复制,如果必要我整理好的数据和代码可以给推文打赏1元获取
欢迎各人关注我的公众号
小明的数据分析条记本
小明的数据分析条记本 公众号 紧张分享:1、R语言和python做数据分析和数据可视化的简朴小例子;2、园艺植物干系转录组学、基因组学、群体遗传学文献阅读条记;3、生物信息学入门学习资料及本身的学习条记!
|