跟着Nature Communications学作图:R语言ggplot2做堆积柱形图展示群体基因组学的结果

简介: 跟着Nature Communications学作图:R语言ggplot2做堆积柱形图展示群体基因组学的结果

论文

Genomic insights into local adaptation and future climate-induced vulnerability of a keystone forest tree in East Asia

https://www.nature.com/articles/s41467-022-34206-8#Sec23

完整的数据分析代码 涉及到群体基因组学

作图数据 ``

https://github.com/jingwanglab/Populus_genomic_prediction_climate_vulnerability

作者的github主页还有很多其他内容 https://github.com/jingwanglab

今天的图推文重复一下论文中的figure2a

论文中提供的代码是

https://github.com/jingwanglab/Populus_genomic_prediction_climate_vulnerability/blob/main/3-Population_genetics/1structure.sh

完整代码


Q2=read.table("pk230_ldpruned.2.Q.txt",header=F)
dim(Q2)
Q3=read.table("pk230_ldpruned.3.Q.txt",header=F)
dim(Q3)

myorder <- c("ZHY-03-1","ZHY-03-10",
             "ZHY-03-12","ZHY-03-17",
             "ZHY-03-2","ZHY-03-3",
             "ZHY-03-4","ZHY-03-6",
             "ZHY-03-7","ZHY-03-9",
             "ZHY-09-1","ZHY-09-11","ZHY-09-15",
             "ZHY-09-16","ZHY-09-17","ZHY-09-18",
             "ZHY-09-2","ZHY-09-6","ZHY-09-8","ZHY-10-1",
             "ZHY-10-11","ZHY-10-13","ZHY-10-14",
             "ZHY-10-15","ZHY-10-16","ZHY-10-3",
             "ZHY-10-4","ZHY-10-6","ZHY-10-9",
             "LiuJQ-MZL-2013-249-1","LiuJQ-MZL-2013-249-10",
             "LiuJQ-MZL-2013-249-3","LiuJQ-MZL-2013-249-4",
             "LiuJQ-MZL-2013-249-5","LiuJQ-MZL-2013-249-6",
             "LiuJQ-MZL-2013-249-7","LiuJQ-MZL-2013-249-8",
             "LiuJQ-MZL-2013-249-9","LiuJQ-MZL-2013-262-1",
             "LiuJQ-MZL-2013-262-10","LiuJQ-MZL-2013-262-11",
             "LiuJQ-MZL-2013-262-3","LiuJQ-MZL-2013-262-5",
             "LiuJQ-MZL-2013-262-6","LiuJQ-MZL-2013-262-7",
             "LiuJQ-MZL-2013-262-8","LiuJQ-MZL-2013-262-9",
             "LiuJQ-MZL-2013-283-1","LiuJQ-MZL-2013-283-10",
             "LiuJQ-MZL-2013-283-12","LiuJQ-MZL-2013-283-15","LiuJQ-MZL-2013-283-3","LiuJQ-MZL-2013-283-4","LiuJQ-MZL-2013-283-5","LiuJQ-MZL-2013-283-6","LiuJQ-MZL-2013-283-8","LiuJQ-MZL-2013-283-9","LiuJQ-MZL-2013-297-1","LiuJQ-MZL-2013-297-10","LiuJQ-MZL-2013-297-2","LiuJQ-MZL-2013-297-3","LiuJQ-MZL-2013-297-4","LiuJQ-MZL-2013-297-5","LiuJQ-MZL-2013-297-6","LiuJQ-MZL-2013-297-7","LiuJQ-MZL-2013-297-8","LiuJQ-MZL-2013-297-9","ZHY-14-1","ZHY-14-12","ZHY-14-13","ZHY-14-2","ZHY-14-3","ZHY-14-4","ZHY-14-5","ZHY-14-6","ZHY-14-7","ZHY-14-9","ZHY-16-1","ZHY-16-12","ZHY-16-13","ZHY-16-14","ZHY-16-15","ZHY-16-2","ZHY-16-3","ZHY-16-4","ZHY-16-6","ZHY-16-8","ZHY-17-1","ZHY-17-12","ZHY-17-13","ZHY-17-14","ZHY-17-15","ZHY-17-5","ZHY-17-6","ZHY-17-8","ZHY-17-9","ZHY-18-10","ZHY-18-13","ZHY-18-2","ZHY-18-3","ZHY-18-4","ZHY-18-5","ZHY-18-7","ZHY-18-8","ZHY-18-9","ZHY-19-10","ZHY-19-11","ZHY-19-12","ZHY-19-13","ZHY-19-14","ZHY-19-15","ZHY-19-5","ZHY-19-6","ZHY-19-8","ZHY-19-9","ZHY-21-1","ZHY-21-11","ZHY-21-12","ZHY-21-14","ZHY-21-2","ZHY-21-3","ZHY-21-4","ZHY-21-5","ZHY-21-7","ZHY-21-8","ZHY-22-1","ZHY-22-10","ZHY-22-11","ZHY-22-12","ZHY-22-3","ZHY-22-6","ZHY-22-7","ZHY-22-8","ZHY-22-9","LiuJQ-MZL-2013-323-0","LiuJQ-MZL-2013-323-10","LiuJQ-MZL-2013-323-11","LiuJQ-MZL-2013-323-12","LiuJQ-MZL-2013-323-13","LiuJQ-MZL-2013-323-4","LiuJQ-MZL-2013-323-5","LiuJQ-MZL-2013-323-6","LiuJQ-MZL-2013-323-7","LiuJQ-MZL-2013-323-9","ZHY-25-10","ZHY-25-11","ZHY-25-12","ZHY-25-13","ZHY-25-14","ZHY-25-3","ZHY-25-4","ZHY-25-7","ZHY-25-8","ZHY-25-9","ZHY-26-1","ZHY-26-10","ZHY-26-11","ZHY-26-12","ZHY-26-13","ZHY-26-15","ZHY-26-2","ZHY-26-3","ZHY-26-4","ZHY-26-8","ZHY-31-1","ZHY-31-10","ZHY-31-11","ZHY-31-12","ZHY-31-2","ZHY-31-3","ZHY-31-4","ZHY-31-7","ZHY-31-8","ZHY-33-1","ZHY-33-10","ZHY-33-11","ZHY-33-12","ZHY-33-3","ZHY-33-6","ZHY-33-7","ZHY-33-8","ZHY-33-9","ZHY-34-1","ZHY-34-11","ZHY-34-12","ZHY-34-13","ZHY-34-14","ZHY-34-2","ZHY-34-4","ZHY-34-5","ZHY-34-7","ZHY-34-9","ZHY-35-1","ZHY-35-10","ZHY-35-2","ZHY-35-3","ZHY-35-4","ZHY-35-5","ZHY-35-6","ZHY-35-7","ZHY-35-8","ZHY-35-9","ZHY-37-10","ZHY-37-11","ZHY-37-12","ZHY-37-15","ZHY-37-2","ZHY-37-3","ZHY-37-4","ZHY-37-6","ZHY-37-8","ZHY-37-9","ZHY-41-1","ZHY-41-10","ZHY-41-11","ZHY-41-12","ZHY-41-13","ZHY-41-2","ZHY-41-4","ZHY-41-6","ZHY-41-7","ZHY-41-9","ZHY-44-1","ZHY-44-10","ZHY-44-2","ZHY-44-3","ZHY-44-4","ZHY-44-5","ZHY-44-6","ZHY-44-9")
length(myorder)

library(tidyverse)
p1<-Q2 %>% 
  mutate(V1=factor(V1,
                   levels = myorder)) %>% 
  pivot_longer(-V1) %>% 
  mutate(name=factor(name,levels = c("V3","V2"))) %>% 
  ggplot(aes(x=V1,y=value,fill=name))+
  geom_bar(stat='identity',width=1,show.legend = FALSE)+
  scale_fill_manual(values = c("V3"="#e9e9e9",
                               "V2"="#e04d72"))+
  theme_bw()+
  theme(panel.grid = element_blank(),
        axis.text.x = element_blank(),
        axis.ticks.x = element_blank())+
  scale_y_continuous(minor_breaks=seq(0,1,0.1),
                     expand = c(0,0),
                     breaks=seq(0,1,0.25))+
  scale_x_discrete(breaks=NULL)+
  labs(x=NULL,y="k=2")


p2<-Q3 %>% 
  mutate(V1=factor(V1,
                   levels = myorder)) %>% 
  pivot_longer(-V1) %>% 
  #mutate(name=factor(name,levels = c("V3","V2"))) %>% 
  ggplot(aes(x=V1,y=value,fill=name))+
  geom_bar(stat='identity',width=1,show.legend = FALSE)+
  scale_fill_manual(values = c("V2"="#e9e9e9",
                               "V3"="#3280c3",
                               "V4"="#e04d72"))+
  theme_bw()+
  theme(panel.grid = element_blank(),
        axis.text.x = element_blank(),
        axis.ticks.x = element_blank())+
  scale_y_continuous(minor_breaks=seq(0,1,0.1),
                     expand = c(0,0),
                     breaks=seq(0,1,0.25))+
  scale_x_discrete(breaks=NULL)+
  labs(x=NULL,y="k=3")

p3<-Q2 %>% 
  mutate(V1=factor(V1,
                   levels = myorder)) %>%
  ggplot()+
  geom_ribbon(aes(x=V1,ymin=0.1,ymax=1),fill="#e04d72")+
  #geom_ribbon(aes(x=164:230,ymin=0.1,ymax=1),fill="#3280c3")+
  theme_bw()+
  theme(panel.grid = element_blank(),
        axis.text = element_blank(),
        axis.ticks = element_blank(),
        panel.border = element_blank(),
        axis.title = element_blank())+
  scale_y_continuous(minor_breaks=seq(0,1,0.1),
                     expand = c(0,0),
                     breaks=seq(0,1,0.25))+
  #scale_x_continuous(breaks=NULL)+
  annotate(geom="text",x=80,y=0,label="South",vjust=-0.5)+
  annotate(geom="text",x=190,y=0,label="North",vjust=-0.5)+
  annotate(geom = "ribbon",x=1:165,ymin=0.5,ymax=1,fill="#e04d72")+
  annotate(geom = "ribbon",x=166:230,ymin=0.5,ymax=1,fill="#3280c3")

library(patchwork)

p1/p2/p3+
  plot_layout(heights = c(4,4,1))

最终结果

image.png

示例数据和代码可以给公众号推文点赞,点击在看,最后留言获取

欢迎大家关注我的公众号

小明的数据分析笔记本

小明的数据分析笔记本 公众号 主要分享:1、R语言和python做数据分析和数据可视化的简单小例子;2、园艺植物相关转录组学、基因组学、群体遗传学文献阅读笔记;3、生物信息学入门学习资料及自己的学习笔记!
相关文章
|
搜索推荐 Linux Python
VET:一个基于R语言的VCF数据提取工具,支持按基因ID、物理位置、样品名称提取指定变异信息
VET:一个基于R语言的VCF数据提取工具,支持按基因ID、物理位置、样品名称提取指定变异信息
|
7月前
|
数据可视化 数据挖掘 索引
R语言层次聚类、多维缩放MDS分类RNA测序(RNA-seq)乳腺发育基因数据可视化|附数据代码2
R语言层次聚类、多维缩放MDS分类RNA测序(RNA-seq)乳腺发育基因数据可视化|附数据代码
|
7月前
|
存储 数据可视化 数据挖掘
R语言绘制圈图、环形热图可视化基因组实战:展示基因数据比较
R语言绘制圈图、环形热图可视化基因组实战:展示基因数据比较
|
7月前
|
存储 数据可视化 数据挖掘
R语言层次聚类、多维缩放MDS分类RNA测序(RNA-seq)乳腺发育基因数据可视化|附数据代码1
R语言层次聚类、多维缩放MDS分类RNA测序(RNA-seq)乳腺发育基因数据可视化|附数据代码
|
7月前
|
数据可视化 定位技术 网络架构
R语言在地图上绘制月亮图、饼状图数据可视化果蝇基因种群
R语言在地图上绘制月亮图、饼状图数据可视化果蝇基因种群
|
7月前
|
数据采集
R语言处理RNA等位基因不平衡(二)
该文档介绍了通过RNA测序数据检测和量化等位基因不平衡的R语言分析流程。首先,RNA测序技术用于研究基因表达的细微变化,包括等位基因特异性表达。接着,通过加载和预处理CSV文件中的计数数据,去除映射错误较多的位点,然后利用二项贝塔分布和优化统计模型(如L-BFGS-B方法)估计等位基因不平衡和分散参数。接下来,为每个基因整合位点信息,通过似然函数最小化计算等位基因不平衡程度,并进行似然比测试以确定显著性。最后,对P值进行FDR校正并输出结果到CSV文件。整个过程涉及数据过滤、建模和统计分析。
55 0
|
7月前
|
数据采集 数据处理
R语言处理DNA等位基因不平衡(一)
该文介绍了等位基因不平衡分析在生物信息学和基因组学中的应用,用于识别受选择压力的基因。等位基因不平衡指基因座上两个等位基因表达比例不均,可能因自然选择等因素引起。研究通过系统分析特定区域的等位基因不平衡,识别关键基因在生物过程或疾病中的作用。示例代码展示了如何处理和分析数据,包括导入数据、预处理、等位基因不平衡测试以及结果输出。该分析适用于DNA数据,未来将推出针对RNA的数据处理方法。
71 0
|
数据可视化 数据挖掘 Linux
科研绘图丨使用R语言Pheatmap包快速绘制基因表达量热图的方法,支持聚类和配色自定义修改
科研绘图丨使用R语言Pheatmap包快速绘制基因表达量热图的方法,支持聚类和配色自定义修改
|
算法 数据可视化 Python
一种基于R语言tidyverse的算法:批量查找SNP位点连锁区内对应的QTL以及基因
一种基于R语言tidyverse的算法:批量查找SNP位点连锁区内对应的QTL以及基因
|
数据挖掘
R语言中如何进行PCA分析?利用ggplot和prcomp绘制基因表达量分析图(下)
R语言中如何进行PCA分析?利用ggplot和prcomp绘制基因表达量分析图(下)