M intention is to represent 3 different layers of information in a ggplot map: 1. The map itself using a MULTIPOLYGON file 2. Kriging estimations using geom_tile() 3. datapoints using geom_point()
I used the following script:
library(rnaturalearth)
library(rnaturalearthdata)
world <- ne_countries(scale = "medium", returnclass = "sf")
windows()
ggplot(data = world) +
geom_sf(color="black",fill="grey90") +
theme(panel.background = element_blank()) +
coord_sf(xlim = c(-12.3, 95), ylim = c(70, 22), expand = FALSE) +
geom_tile(data = myKrige, aes(x= x1, y= x2, fill =var1.pred)) +
geom_point(data = roh, aes(x = LON, y = LAT))
In this script I used three datasets: world (a MULTIPOLYGON obtained from rnaturalearthdata), myKrige (data frame obtained from a spatialPointsDataFrame) and roh (data frame with latitude and longitude data points).
This is the figure my script produces:
As you can see the different layers are on top of each other. But I would like to merge nicely the geom_tile with the base plot.
Any idea how can I do it easily. Or should I rethink the complete figure?
fill = NA. - pasipasicoord_sf()function to the end of the ggplot call. If you restrict your coordinate box further down in the ggplot call "change" the data, as you seem to do in geom_tile(data=...), it "restarts" the plotting area. Try to move the coord_sf() after that - Marcelo Avila