我想将SpatVector对象转换为数据框以在 ggplot2 中使用。
pkgs <- c("geodata", "raster", "ggplot2", "tidy")
lapply(pkgs, require, character.only = TRUE)
boundary_GB <- geodata::gadm(country = "GB", path = tempdir(), resolution = 2, level = 1)
Run Code Online (Sandbox Code Playgroud)
我目前的方法需要很长时间:
boundary_GB_df <- broom::tidy(methods::as(boundary_GB, "Spatial"))
Run Code Online (Sandbox Code Playgroud)
剧情:
ggplot(data = boundary_GB_df, mapping = aes(x = long, y = lat, group = group)) +
geom_polygon(fill = NA, colour = "black")
Run Code Online (Sandbox Code Playgroud)
我对 SpatVector 对象没有经验,有更快的方法吗?
我知道 tidyterra 包(即 tidyterra::geom_spatvector())。
谢谢