小编use*_*627的帖子

将 SpatVector 对象转换为数据框以在 ggplot2 中使用

我想将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())。

谢谢

r tidy ggplot2 fortify terra

3
推荐指数
1
解决办法
1269
查看次数

标签 统计

fortify ×1

ggplot2 ×1

r ×1

terra ×1

tidy ×1