論文
A global reptile assessment highlights shared conservation needs of tetrapods
https://www.nature.com/articles/s41586-022-04664-7#Sec33
數(shù)據(jù)代碼鏈接
https://github.com/j-marin/Global-reptile-assessment-
今天的推文學(xué)習(xí)一下推文中的Figure 3的簇狀柱形圖枫耳,沒(méi)有找到論文中的作圖代碼,但是找到了原始數(shù)據(jù)集,有了原始數(shù)據(jù)集就可以自己寫(xiě)代碼來(lái)做這個(gè)圖
部分示例數(shù)據(jù)集
加載需要用到的R包
library(readxl)
library(ggplot2)
library(tidyverse)
library(patchwork)
Figure 3a
dat01<-read_excel("data/20220630/41586_2022_4664_MOESM4_ESM.xlsx",
sheet = "Fig 3a")
head(dat01)
dim(dat01)
dat01$Threat<-factor(dat01$Threat,
levels = dat01$Threat %>% unique())
ggplot(data=dat01,aes(x=Threat,y=n,fill=className))+
geom_bar(stat="identity",position = "dodge")+
theme_classic()+
geom_vline(xintercept = 5.5,lty="dashed")+
geom_vline(xintercept = 9.5,lty="dashed")+
annotate(geom = "text",x=2.5,y=0.9,label="Habitat destruction")+
annotate(geom = "text",x=7.5,y=0.9,label="Habitat change")+
annotate(geom = "text",x=11,y=0.9,label="Other")+
theme(legend.position = "bottom",
axis.text.x = element_text(angle=60,hjust = 1,vjust = 1),
legend.title = element_blank())+
labs(x=NULL,y="Species threatened (%)")+
scale_fill_manual(values = c("#936eaa","#401f51",
"#5f6798","#de6eaa"))+
scale_y_continuous(labels = function(x){x*100}) -> p1
p1
Figure 3b
和Figure 3a是一樣的病附,唯一的區(qū)別是配色不一樣
dat02<-read_excel("data/20220630/41586_2022_4664_MOESM4_ESM.xlsx",
sheet = "Fig 3b")
head(dat02)
dim(dat02)
dat02$Threat<-factor(dat02$Threat,
levels = dat02$Threat %>% unique())
ggplot(data=dat02,aes(x=Threat,y=n,fill=className))+
geom_bar(stat="identity",position = "dodge")+
theme_classic()+
geom_vline(xintercept = 5.5,lty="dashed")+
geom_vline(xintercept = 9.5,lty="dashed")+
annotate(geom = "text",x=2.5,y=0.9,label="Habitat destruction")+
annotate(geom = "text",x=7.5,y=0.9,label="Habitat change")+
annotate(geom = "text",x=11,y=0.9,label="Other")+
theme(legend.position = "bottom",
axis.text.x = element_text(angle=60,hjust = 1,vjust = 1),
legend.title = element_blank())+
labs(x=NULL,y="Species threatened (%)")+
scale_fill_manual(values = c("#4868af","#e41f24",
"#edb91d","#973692"))+
scale_y_continuous(labels = function(x){x*100}) -> p2
p2
最后是拼圖
p1/p2 + plot_annotation(tag_levels = "a")
論文中的figure4也是簇狀柱形圖宫纬,感興趣的可以自己試著復(fù)現(xiàn)一下
示例數(shù)據(jù)和代碼可以自己到論文中獲取训貌,或者給本篇推文點(diǎn)贊既棺,點(diǎn)擊在看尺栖,然后留言獲取
歡迎大家關(guān)注我的公眾號(hào)
小明的數(shù)據(jù)分析筆記本
小明的數(shù)據(jù)分析筆記本 公眾號(hào) 主要分享:1嫡纠、R語(yǔ)言和python做數(shù)據(jù)分析和數(shù)據(jù)可視化的簡(jiǎn)單小例子;2决瞳、園藝植物相關(guān)轉(zhuǎn)錄組學(xué)货徙、基因組學(xué)、群體遺傳學(xué)文獻(xiàn)閱讀筆記皮胡;3痴颊、生物信息學(xué)入門(mén)學(xué)習(xí)資料及自己的學(xué)習(xí)筆記!