英文:
Subsetted states look very weird with function raster::getData
问题
我使用 raster::getData
获取了一个 Large SpatialPolygonsDataFrame
,如下所示:
states <- raster::getData("GADM", country = "United States", level = 1)
我对 IL 和 WI 进行了子集化:
statesilwi <- states[states$NAME_1 == "Illinois" | states$NAME_1 == "Wisconsin",]
但当我绘制它时,伊利诺伊州看起来有点奇怪,为什么会这样,有没有办法修复它?
plot(statesilwi)
英文:
I used raster::getData
to obtain a Large SpatialPolygonsDataFrame
details below
states <- raster::getData("GADM", country = "United States", level = 1
I subsetted IL and WI...
statesilwi <- states[states$NAME_1 == "Illinois" | states$NAME_1 == "Wisconsin",]
But when I plot it, it Illinois looks a little bit funky, why is this happening and is there a way to fix it?
plot(statesilwi)
答案1
得分: 1
"looks a bit funky" 不太清楚。但我觉得 @rawr 是正确的。密歇根湖的一部分属于伊利诺伊州。
你可以像这样移除密歇根湖:
library(terra)
library(geodata)
us <- geodata::gadm("United States", level = 2, path=".")
us <- us[us$TYPE_2 != "Water body", ]
s <- us[us$NAME_1 %in% c("Illinois", "Wisconsin"),]
s <- aggregate(s, "NAME_1")
plot(s)
英文:
"looks a bit funky" is not very clear. But it seems to me that @rawr is correct. A part of Lake Michigan belongs to Illinois.
You can remove Lake Michigan like this:
library(terra)
library(geodata)
us <- geodata::gadm("United States", level = 2, path=".")
us <- us[us$TYPE_2 != "Water body", ]
s <- us[us$NAME_1 %in% c("Illinois", "Wisconsin"),]
s <- aggregate(s, "NAME_1")
plot(s)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论