在 ggvis 中创建包括州边界的美国地图

Creating US Map Including State Borders in ggvis

我正在尝试制作一张美国地图,以后可以向其中添加交互式图层。但是,根据创建的多边形,似乎存在顺序问题;我用几种不同的方式订购了它们,其中 none 似乎工作正常。任何帮助将不胜感激。

library(ggplot2) 
library(ggvis) 
library(dplyr) 

mdat<-map_data("state") 

mdat %>% 
  arrange(group,order) %>% 
  ggvis(x=~long,y=~lat) %>% 
  layer_paths() 

我从 post 链接到一个更完整的示例(包括对美国连续 48 个州使用更明智的投影):

library(ggplot2)
library(ggvis)
library(dplyr)
library(rgdal)
library(httr)

# decent US shapefile and httr lets us only d/l when needed
stop_for_status(GET("http://eric.clst.org/wupl/Stuff/gz_2010_us_040_00_500k.json",
                write_disk("us.geojson"), progress()))

states <- readOGR("us.geojson", "OGRGeoJSON")
states <- states[!states$NAME %in% c("Alaska", "Hawaii", "Puerto Rico", "District of Columbia"),]
states_aea <- spTransform(states, CRS("+proj=laea +lat_0=45 +lon_0=-100 +x_0=0 +y_0=0 +a=6370997 +b=6370997 +units=m +no_defs"))

states_map <- fortify(states_aea, region="NAME")

states_map %>%
  group_by(group) %>%
  ggvis(~long, ~lat) %>%
  layer_paths(strokeOpacity := 0.5, strokeWidth := 0.5) %>%
  hide_axis("x") %>% hide_axis("y") %>%
  set_options(width=960, height=600, keep_aspect=TRUE)