I'm trying to plot polygons in R using
ggplot2. In GRASS, QGIS and normal R the map renders fine, but
ggplot2seems to have some kind of topological difficultes I can't explain. With normal R it looks like this:
library(rgdal) library(ggplot2) regions <- readOGR(dir, layer) plot(regions)
ggplot() + geom_polygon(data=regions, aes(long, lat))
To add to the confusion,
gplot2is connecting polygons that have absolutely nothing to do with each other - Iceland to Ireland, for instance. How can I fix the plot?
A group aesthetic is missing:
ggplot() + geom_polygon(data=fortify(regions), aes(long, lat, group=group))
Otherwise the last point of a polygon is connected with the first point of the next polygon.
See also here: