If you did not find the geospatial data you need in existing R packages (see the map section), you need to find this information elsewhere on the web.
It will often be stored as a
.geomJSON format. This post explains how to read it.
Note: if you found a
shapefile, read this post instead.
You need to dig the internet to find the geoJSON file you are interested in. For instance, this URL provides a file containing french region boundaries.
You can load it in R with:
That’s it! You now have a geospatial object called
spdf. I strongly advise to read this post to learn how to manipulate it.
Just in case, here is how to plot it in base R and with
plot() function knows how to plot a geospatial object. Thus you just need to pass it
spdf and add a couple of options to customize the output.
It is totally possible (and advised imo) to build the map with ggplot2. However, ggplot2 takes as input data frames, not geospatial data.
The geospatial object thus needs to be transformed using the
tidy() function of the
Once the data frame is created, it is plotted using the
geom_polygon() function as described below.