I am fairly new in doing GIS work in R, but I thought this would be a nice situation to get my feet wet.
Here is the situation: I need to create multiple plots with the same background, the same polygon layer from a shapefile, but a different selection of points (another shapefile), each time an other animal species. So I would think to create a loop where I run through a list of species, create the plot (either ggplot of tmap, or something else) and save the plot as a PNG.
I loaded the shapefiles with
st_read() (from the
sf package), and making the selection and put them in the plot is fairly straight forward. But I have a problem when I want to add the background map.
A few things I have tried:
Download OSM tiles using the
read_osm() function from
tmaptools. But my shapes are in a local Projection (Amersfoort/RD New) and the map is slightly misaligned with my shapefile for some reason.
Download tiles with
get_map() from the
ggmap package, but this fails with a '400 Bad Request'
Export a TIFF of the background map I want in QGIS is and try to import it into R using the raster function. This solves the alignment, but the layer is not in colour.
I think the last route might be the simplest, but than my question is: how do I export a map in QGIS that I can import in R to display as a coloured background map in ggplot, ggmap or tmap.
But also other suggestions, I am very new to this, and there is a lot of different information out there so I might be doing this all wrong...