【问题标题】:Unable To Overlay Counties On Geographic Map In R?无法在 R 中的地理地图上覆盖县?
【发布时间】:2020-07-08 21:48:16
【问题描述】:

我正在尝试使用in an earlier post 提供的代码生成明尼苏达州的地图,包括其县。

虽然我可以使用以下代码生成明尼苏达州地图:

Minnesota<-get_map(location = "Minnesota", 
               zoom = 6, source = "google", maptype="roadmap")

但是,我无法使用以下代码生成县的细分:

##Get Minnesota Counties
    counties <- map_data("county")
    mn_county <- subset(counties, region == 'minnesota')
    Minnesota + 
      geom_polygon(data = mn_county, aes(x=long, y=lat, group = group), fill = NA, color = "red")

我收到以下错误消息,而不是获得带有县级轮廓的地图:

Error in Minnesota + geom_polygon(data = mn_county, aes(x = long, y = lat,  : 
  non-numeric argument to binary operator
In addition: Warning message:
Incompatible methods ("Ops.raster", "+.gg") for "+" 

【问题讨论】:

    标签: r google-maps heatmap ggmap


    【解决方案1】:

    你必须使用ggmap(Minnesota)来映射base_layer:

    library(ggplot2)
    library(ggmap)
    
    Minnesota<-get_map(location = "Minnesota", 
                       zoom = 6, source = "google", maptype="roadmap")
    
    ##Get Minnesota Counties
    counties <- map_data("county")
    mn_county <- subset(counties, region == 'minnesota')
    ggmap(Minnesota) + 
      geom_polygon(data = mn_county, aes(x=long, y=lat, group = group), fill = NA, color = "red")
    

    reprex package (v0.3.0) 于 2020 年 3 月 28 日创建

    【讨论】:

      猜你喜欢
      • 2021-05-29
      • 1970-01-01
      • 1970-01-01
      • 2021-06-29
      • 1970-01-01
      • 2012-12-06
      • 1970-01-01
      • 1970-01-01
      • 2019-04-11
      相关资源
      最近更新 更多