[R-sig-Geo] Tearing of polygons using ggmap & readOGR
Roger Bivand
Roger.Bivand at nhh.no
Sun Jan 31 21:35:56 CET 2016
On Sun, 31 Jan 2016, Tyler Frazier wrote:
> I'm trying to incorporate a simple shapefile of US states with ggmap and keep getting "tearing" of my polygons. I tried changing group=id to group=group which seemed to partially solve the problem, but not entirely.
>
> library(rgdal)
>
> states <- readOGR(dsn="shapefiles", layer="states")
>
> proj4string(states)
>
> [1] "+proj=longlat +datum=NAD83 +no_defs +ellps=GRS80 +towgs84=0,0,0"
>
> states <- spTransform(states, CRS("+proj=longlat +datum=WGS84"))
Unnecessary, as you should know from the +towgs84= tag.
>
> states <- fortify(states)
The fortify methods turn data from marine animals with structure into fish
soup (a data frame adding attribute values spuriously to each coordinate,
I believe). Unless the objects are exactly as fortify wants them, it
derails.
Do you know that they were polygons? Where did the shapefile come
from? Did you plot it? Did you check that it contained what you thought it
contained (summary())?
Have you considered alternatives (tmap, mapview, ...)?
>
> sstates <- get_map(location = c(-81, 35, -69, 45), zoom = 4, maptype = "watercolor")
>
> sstates <- ggmap(sstates)
>
> sstates <- sstates + geom_polygon(aes(x = long, y = lat, group=group), data = states, color ="white", fill ="orangered4", alpha = .4, size = .2)
>
> Here is an image of the output.
>
> http://pasteboard.co/1d7kiRfw.png <http://pasteboard.co/1d7kiRfw.png>
>
Image posted OK, but posting HTML (unnecessary).
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>
--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 91 00
e-mail: Roger.Bivand at nhh.no
http://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en
http://depsy.org/person/434412
More information about the R-sig-Geo
mailing list