I have a raster data and polygons of parks and I want to overlap it on the raster. When I add the polygon it shows here but on ggplot how I add polygons (polygons of parks is like round shapes)on my raster data through ggplot2,. My code is attached below.
r <- raster(t((volcano[,ncol(volcano):1] - 94) * 4.95))
pg <- readOGR("E:/park/1aa.shp") # loadshapfile
plot(r)
plot(pg, add= TRUE,) # it appears here like first picture (left).
But how can I add this polygons o parks in my ggplot 2. My code of ggplot 2 is attached below.
centile90 <- quantile(r, 0.90)
df <- as.data.frame(as(r, "SpatialPixelsDataFrame"))
colnames(df) <- c("value", "x", "y")
library(ggplot2)
mybreaks <- seq(0, 500, 50)
ggplot(df, aes(x, y, z = value)) +
geom_contour_filled(breaks = mybreaks) +
geom_contour(breaks = centile90, colour = "pink",
size = 0.5) +
scale_fill_manual(values = hcl.colors(length(mybreaks) - 3, "Zissou1", rev = FALSE)) +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0)) +
theme_classic() +
theme()
Help is needed how to add ** pg (polygon) ** in my ggplot2 code.
Update 1 Description of polygon data




sphas basically deprecated that package and is focusing all new development on the newersfpackage, it's now easier to plot polygons onggplot2plots usingsfinstead ofsp. Try reading your shapefile in withsf::st_read()instead ofreadOGR, then you can add ageom_sf()to your plot. See r-spatial.github.io/sf/articles/sf5.html1aa.shpfile? So we can reproduce your problem.