使用 tmap 和简单的功能分解美国各州的部分

Breaking out section of US States with tmap and simple features

我正在尝试使用 tmap 和简单的功能制作一张美国各州与该国其他地区分开的地图。我正在将坐标调整到所需的数量(在下面的示例中是东部地区)——但出于某种原因,佛罗里达州和纽约州拒绝移动。我尝试在循环外手动调整,结果相同。如果我想将一个 sf 对象移动一个常量,接近它的最佳方法是什么?

另外 - 为什么密歇根看起来像融化在密歇根湖中一样?

library(tmap)
library(tmaptools)
library(tigris)

us_geo <- states(class = "sf")

us_geo$PADD[us_geo$NAME %in% 
              c("Maine", "Vermont", "New Hampshire", "Massachusetts", "Connecticut", "Rhode Island",
                "New York", "Pennsylvania", "New Jersey", "Delaware", "District of Columbia", "Maryland",
                "West Virginia", "Virginia", "North Carolina", "South Carolina", "Georgia", "Florida")] <- "East Coast"

us_geo$PADD[us_geo$NAME %in% 
              c("South Dakota", "North Dakota","Nebraska", "Kansas", "Oklahoma", 
                "Minnesota", "Iowa", "Missouri", "Wisconsin", "Illinois", "Indiana",
                "Michigan", "Ohio", "Kentucky", "Tennessee")] <- "Midwest"

us_geo$PADD[us_geo$NAME %in% 
              c("New Mexico", "Texas", "Arkansas", "Louisiana", "Alabama", "Mississippi")] <- "Gulf Coast"

us_geo$PADD[us_geo$NAME %in% 
              c("Montana", "Idaho", "Wyoming", "Utah", "Colorado")] <- "Rocky Mountain"

us_geo$PADD[us_geo$NAME %in% 
              c("Washington", "Oregon", "Nevada", "Arizona", "California")] <- "West Coast"

us_geo <- us_geo[!is.na(us_geo$PADD),]



x <- grep("East", us_geo$PADD)

for(i in x){
  us_geo[i,]$geometry[[1]][[1]][[1]][,1] <- us_geo[i,]$geometry[[1]][[1]][[1]][,1] +5
}

qtm(us_geo)

我实际上并没有移动 MULTIPOLYGON 中的所有对象。我想前面的 multi- 这个词让我很困惑。只需要添加另一个循环。另外,我改变了让密歇根重新出现的决议。

library(tmap)
library(tmaptools)
library(tigris)

us_geo <- states(class = "sf", res = "5m", cb = TRUE)

us_geo$PADD[us_geo$NAME %in% 
              c("Maine", "Vermont", "New Hampshire", "Massachusetts", "Connecticut", "Rhode Island",
                "New York", "Pennsylvania", "New Jersey", "Delaware", "District of Columbia", "Maryland",
                "West Virginia", "Virginia", "North Carolina", "South Carolina", "Georgia", "Florida")] <- "East Coast"

us_geo$PADD[us_geo$NAME %in% 
              c("South Dakota", "North Dakota","Nebraska", "Kansas", "Oklahoma", 
                "Minnesota", "Iowa", "Missouri", "Wisconsin", "Illinois", "Indiana",
                "Michigan", "Ohio", "Kentucky", "Tennessee")] <- "Midwest"

us_geo$PADD[us_geo$NAME %in% 
              c("New Mexico", "Texas", "Arkansas", "Louisiana", "Alabama", "Mississippi")] <- "Gulf Coast"

us_geo$PADD[us_geo$NAME %in% 
              c("Montana", "Idaho", "Wyoming", "Utah", "Colorado")] <- "Rocky Mountain"

us_geo$PADD[us_geo$NAME %in% 
              c("Washington", "Oregon", "Nevada", "Arizona", "California")] <- "West Coast"

us_geo <- us_geo[!is.na(us_geo$PADD),]

qtm(us_geo)

x <- grep("East", us_geo$PADD)

for(i in x){
  for(j in 1:length(us_geo[i,]$geometry[[1]])){
  us_geo[i,]$geometry[[1]][[j]][[1]][,1] <- us_geo[i,]$geometry[[1]][[j]][[1]][,1] +5
  }
}

qtm(us_geo)