在ggmap上覆盖形状文件

时间:2016-04-11 20:38:27

标签: r ggplot2 ggmap

我在ggmap地图上叠加形状文件时遇到问题。

当我单独运行时,形状文件很好,见下图。

library(ggmap)
library(grid)

la <- get_map(location="Los Angeles County", zoom=9)

# get base map layer
gg <- ggmap(la)

 library(broom)

  LaCountyTracts <- CalifCensusTracts %>% 
   tidy(region = "GEOID") %>%
   filter(grepl("06037", id))

 ggplot(LaCountyTracts, aes(long, lat, group = group) ) +
      geom_polygon(   fill = "grey40", 
           colour = "grey90", alpha = .7, size = .05) +
      coord_map() +
      theme_minimal() 

enter image description here

当组合ggmap和形状文件时,下面的代码会产生变形的形状图层。

 gg + geom_polygon(data=LaCountyTracts,aes(x=long, y=lat,group=group),
                      colour = "grey90", alpha = .7, size = .05)

enter image description here

1 个答案:

答案 0 :(得分:0)

更改了这一行
la <- get_map(location="Los Angeles County", zoom=9)

la <- get_map(location="Los Angeles County", zoom = 8)

并修复了问题