欢迎关注R语言数据分析指南
本节来复现nature communications上一篇文章中地图的绘制方法,下面来进行复现过程,由于未找到作者提供的数据信息,小编自己构建了绘图文件因此结果与原图有出入仅供参考。整张图均使用R代码进行绘制
Land-use diversity predicts regional bird taxonomic and functional richness worldwide
加载R包
# install.packages("rnaturalearthdata")
# install.packages("tidygeocoder")
library(tidygeocoder)
library(tidyverse)
library(sf)
library(camcorder)
library(scico)
library(rnaturalearth)
library(terra)
library(tidyterra)
library(geodata)
library(cowplot)
library(ggsci)
绘制点图
df1 <- read_tsv("data.xls") %>% filter(type=="Taxonomic richness") %>%
select(5:9) %>%
group_by(REALM) %>%
slice_head(n=1)
df1$REALM <- factor(df$REALM,levels = c("Nearctic","Palearctic","Indomalayan","Neotropic","Afrotropic","Australasia"))
plot1 <- df1 %>% ggplot(aes(y = fct_rev(REALM))) +
theme_bw()+
geom_errorbarh(aes(xmin=Lower_ci,xmax=Upper_ci),height=0.1) +
geom_point(aes(x=visregFit,color=REALM),fill="black",size=3,show.legend = F) +
labs(x="Taxonomic richness",y=NULL)+
scale_color_npg()+
theme(axis.ticks.y= element_blank(),
axis.title.y= element_blank(),
axis.title.x = element_text(color="black",size=8,face="bold"),
axis.text.y=element_text(color="black",size=8,face="bold"),
axis.text.x=element_text(color="black",size=8,face="bold"))
df2 <- read_tsv("data.xls") %>%
filter(type=="Functional richness") %>%
select(5:9) %>%
group_by(REALM) %>%
slice_head(n=1)
df2$REALM <- factor(df$REALM,levels = c("Nearctic","Palearctic","Indomalayan","Neotropic","Afrotropic","Australasia"))
plot2 <- df2 %>% ggplot(aes(y = fct_rev(REALM))) +
theme_bw()+
geom_errorbarh(aes(xmin=Lower_ci,xmax=Upper_ci),height=0.1) +
geom_point(aes(x=visregFit,color=REALM),fill="black",size=3,show.legend = F) +
labs(x="Functional richness",y=NULL)+
scale_color_npg()+
theme(axis.ticks.y= element_blank(),
axis.title.y= element_blank(),
axis.title.x = element_text(color="black",size=8,face="bold"),
axis.text.y=element_text(color="black",size=8,face="bold"),
axis.text.x=element_text(color="black",size=8,face="bold"))
好了本节介绍到此结束,非常简单的一个案例喜欢的观众老爷欢迎分享转发,更多精彩案例欢迎关注我的公粽号R语言数据分析指南