I have a SpatialPolygonsDataFrame containing multiple polygons that I want to plot in ggplot2. However, when I try converting my SpatialPolygonsDataFrame to a dataframe (required by ggplot2) via the fortify
{ggplot2} function, polygons that overlap are merged. I know this is where the problem is because View(as.data.frame(data_pre_fortify))
and View(data_post_fortify)
tell me the number of polygons before & after fortifying.
Currently my fortify function simply calls fortify(data_post_fortify, region = "id")
.
Can this merging of polygons be avoided, and if so, how?
Whilst this is by no means a perfect solution, I have managed to work around the issue by creating three SpatialPolygonsDataFrames, each containing only polygons that don't overlap (so overlapping polygons are split between different SpatialPolygonsDataFrames, and then fortifying these on their own. When it came to plotting I therefore had three geom_polygon layers, each calling one of the dataframes containing a subset of polygons.
I realise this isn't a great solution — colour/fill aesthetics cannot be added for all polygons together, plus this manual sorting of overlapping polygons may not be very time effective for larger/more overlapping datasets — so any further answers are very welcome!