Margaret
Margaret

Reputation: 5929

Bizarre polygons from a shapefile

I'm trying to apply a shapefile to a ggmaps map, but it's giving me really weird results. The shapefile in question is the "Statistical Local Area" (groups similar to postcode) shapefile from the Australian Bureau of Statistics available here.

SLA Shapefile applied at zoom level 4

Normally I might think that it's a problem of cut off edge points, but I'm hitting it even at zoom level 1 (in fact it looks even worse): SLA Shapefile applied at zoom level 1

Here's some code I used to produce the charts above:

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))

Am I doing something wrong, or is the shapefile incorrectly configured somehow?

Upvotes: 3

Views: 437

Answers (1)

neilfws
neilfws

Reputation: 33802

I think you just need to (optionally) fortify the variable slas, don't forget to group and make the boundaries visible with a color:

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

Upvotes: 7

Related Questions