跟着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、生物信息学入门学习资料及自己的学习笔记!

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 211,948评论 6 492
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 90,371评论 3 385
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 157,490评论 0 348
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 56,521评论 1 284
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 65,627评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 49,842评论 1 290
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,997评论 3 408
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 37,741评论 0 268
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,203评论 1 303
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 36,534评论 2 327
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 38,673评论 1 341
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,339评论 4 330
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,955评论 3 313
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 30,770评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,000评论 1 266
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 46,394评论 2 360
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 43,562评论 2 349

推荐阅读更多精彩内容