0

I'm trying to plot polygons in R using ggplot2. In GRASS, QGIS and normal R the map renders fine, but ggplot2 seems 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)

Plot with R

And with ggplot2:

ggplot() + geom_polygon(data=regions, aes(long, lat))

Plot with ggplot2

To add to the confusion, gplot2 is connecting polygons that have absolutely nothing to do with each other - Iceland to Ireland, for instance. How can I fix the plot?

3

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:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.