2017-10-05 66 views
3

我想将shapefile应用于ggmaps贴图,但它给了我很奇怪的结果。所讨论的shapefile是澳大利亚统计局提供的“统计局域”(类似于邮编的组)形状文件,可用于hereshapefile中的奇怪多边形

SLA Shapefile applied at zoom level 4

通常我会认为这是切断边缘点的问题,但我打它,即使在缩放级别1(其实它看起来更糟): SLA Shapefile applied at zoom level 1

这里的一些代码我用来产生上面的图表:

library(tidyverse) 
library(ggmap) 
library(rgdal) 

slas <- readOGR(dsn="SLA",layer="SLA11aAust") 

aus4 <- get_map("Australia",zoom=4) 
ggmap(aus4) 

ggmap(aus4)+ 
    geom_polygon(data=slas, aes(x=long,y=lat)) 

aus1 <- get_map("Australia",zoom=1) 
ggmap(aus1) 

ggmap(aus1)+ 
    geom_polygon(data=slas, aes(x=long,y=lat)) 

我做错了什么,或者是shapefile以某种方式错误配置?

回答

6

我想你只需要(可选)fortify变量slas,不要忘了group,使边界与彩色可视:

slas <- fortify(slas, region = "SLA_CODE11") 
ggmap(aus4) + 
    geom_polygon(data = slas2, color = "white", aes(x = long, y = lat, group = group)) 

enter image description here

+0

你说得对,那看起来好多了。什么'fortify'呢?该文件现在只是说“去使用'扫帚'包,而不是”,这是没有用的。 – Margaret

+2

'fortify'将'slas'从'SpatialPolygonsDataFrame'转换为常规'data.frame'。严格地讲,这不是必要的;缺少的关键是'group = group'参数。 – neilfws

相关问题