【发布时间】:2022-11-15 08:24:49
【问题描述】:
这是我第一次在 ggplot 中使用地图。我需要创建 90 个植物物种分布图。
因此,我设置了 API 以从 Plant of the World Online 获取数据,并从 World Geographical Scheme for Recording Plant Distributions https://github.com/tdwg/wgsrpd 获取 shp
require(kewr)#to connect to POWO APIs
#getting data from POWO
id.powo <- search_wcvp("Camellia japonica")
id.powo<- id.powo$results[[1]]$id
r <- lookup_powo(id.powo, distribution = TRUE)
native <- r$distribution$natives
introduced <- r$distribution$introduced
tdwg.native.name <- list()
for (i in 1:length(native)){
tdwg.native.name[[i]]<- native[[i]]$name
}
tdwg.native.name <- unlist(tdwg.native.name)
col.native <- c("#B8DE95") #pastel green for native
tdwg.introduced.name <- list()
for (i in 1:length(introduced)){
tdwg.introduced.code[[i]]<- introduced[[i]]$name
}
tdwg.introduced.name <- unlist(tdwg.introduced.code)
#col.introduced <- c("#9F6CCC") #pastel violet for introduced
#creating the map
install.packages("remotes")
remotes::install_github("barnabywalker/bazr")
library(bazr)
I downloaded the shp from https://github.com/tdwg/wgsrpd and then loaded in r
tdwg_level3.shp<- read_sf("/Users/...d/wgsrpd-master/level3/level3.shp")
tdwg_level3.shp.robinson<- st_transform(tdwg_level3.shp, crs ="+proj=robin +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs")
ggplot() +
geom_sf(data = tdwg_level3.shp.robinson)
此外,地图看起来很拥挤,因为某些区域被分区,并且有小岛使地图看起来很脏。最后,没有必要绘制南极洲......
此地图是使用此脚本构建的https://gist.github.com/valentinitnelav/065af8eba2d9455d9407e5d3890f6f86
我需要制作大约 100 张地图,每个物种一张。我将在数据框列中列出代码 id.powo 然后循环代码。
id.powo.list<- c("17414550-1", "296290-1", "263221-1")
谢谢
【问题讨论】: