mapsf
has just landed on CRAN.
mapsf
helps to design various cartographic representations such as proportional symbols, choropleth or typology maps. It also offers several functions to display layout elements that improve the graphic presentation of maps (e.g. scale bar, north arrow, title, labels). mapsf
maps sf
objects on base
graphics.
Main features
mf_map()
mf_map() is the main function of mapsf, it displays map layers on a georeferenced plot. It has three main arguments: x
, an sf
object, var
, the name(s) of a variable(s) to map and type
, the map layer type.
Example of choropleth map:
Here are examples of each type of map:
Map Layout
Along with the cartographic functions, some other functions are dedicated to layout design (e.g. legends, scale bar, north arrow, title, credits…).
Themes
mf_theme()
defines a map theme. It sets the margins of the figure, a background color, a foreground color and some title parameters. A set of theme is included in the package and it is possible to create custom ones.
Here are the built-in themes:
Insets
One can create an inset map with mf_inset_on()
.
With mf_inset_on(x = "worldmap")
and mf_worldmap()
a world scale situation map is created:
Inset are not limited to maps, in this example we have created an inset to display a “histogram-legend”.
Map export
mf_init()
plots an invisible layer with the extent of a spatial object.
Note the use of expandBB
to expand the map space on one (or several) side of the figure. This argument can be useful to save some space to display legends or insets.
The mf_init()
function can be used to export maps in raster (PNG) or vector formats (SVG). The size of the exported map will fit the height/width ratio of a spatial object (x
). It allows to produce well fitted figures without excessive margins.
Syntactic Sugar
mapsf
is, mostly, compatible with the pipe syntax (%>%
from magrittr
, and likely the future base
|>
) :
Développement
The development of mapsf
happens on GitHub. This project uses conventional commits that force the creation of an explicit commit history.
Unlike cartography
, mapsf
will not be enriched by “exotic” map representations (waffle maps, dicontinuities, map tiles…). If these mapping methods are needed, they will be developped in one or several complementary packages (e.g. maptiles for downloading and displaying map tiles).
But cartography
…
cartography
was created in 2015. It was based on sp
, rgdal
and rgeos
. V2.0.0 introduced sf
compatibility and internally switched to sf
functions and objects. But the general API was not significatly modified.
Some initial choices (camelCase, ultra-verbose function and argument names) were not the most inspired. This, plus the need to ensure a correct minimum backward compatibility (132k downloads for cartography
through the RStudio CRAN), tend to hinder the development of new feature.
So, mapsf
is the successor of cartography
. There are no plans for new features or enhancements in cartography
, but basic maintenance and support will continue indefinitely. Existing projects that use cartography
can safely continue to use cartography
. New projects should use mapsf
because it is friendlier, lighter and more robust.
See mapsf
vignette to migrate from cartography
to mapsf
.
Acknowledgements
I would like to thank Hugues Pecout for its beautiful hex logo and its always relevant feedback on the user-friendliness of the package website, Diego Hernangómez for its work on the design of package website, and of course authors and contributors of the sf
package and the essential GEOS
, GDAL
and PROJ
libraries.
OpenEdition vous propose de citer ce billet de la manière suivante :
Timothée Giraud (4 mars 2021). The mapsf package. R Géomatique. Consulté le 9 décembre 2024 à l’adresse https://doi.org/10.58079/tp4p
Bonjour,
Tout d’abord merci pour votre package qui m’est très utile dans les productions que je réalise. J’ai deux questions à vous poser :
– La barre d’échelle affiche une valeur incohérente (par exemple, 3e-04 pour un département comme la Seine-Maritime). Je vois dans l’aide de la fonction mf_scale que le problème peut venir de la projection. Avez vous une idée de comment la corriger ? J’ai préparé ma couche avec Qgis.
– Sur les cercles proportionnelles, est-il possible de régler la transparence de la couleur à l’intérieur des cercles ?
En vous remerciant pour votre aide.
Bonjour,
– Comme l’indique la documentation (“This scale bar is not accurate on unprojected (long/lat) maps.”) la fonction mf_scale() ne fonctionne pas avec des données non projetées (en longitude / latitude, comme le WGS84 par exemple). La solution est donc d’utiliser un système de référence de coordonnées (CRS) projetées (“EPSG:2154”, c’est à dire Lambert 93, pour la France).
– Vous pouvez indiquer des couleurs au format hexadécimal pour la couleur des cercles : par exemple “#FF000080” pour un rouge avec 50% de transparence.
T.
Merci beaucoup pour votre retour.
Is there mapsf functionality or workarounds for choropleth fill patterns ( hatching, stippling, etc.) ? It is very convenient for 2-dimensional data in grayscale.
Unfortunatly there is no solution in mapsf to create such patterns. However there is a hatchedLayer() function in cartography and it should be possible to use this function in a map that also use mapsf.
See http://riatelab.github.io/cartography/docs/reference/hatchedLayer.html
Hi! Thanks for your website, it helps me a lot. I am beggining in cartography (i am a mathematician). mtq is for Martinique, if i would like the same for Gironde (France) how can i do? Thank you
The mtq dataset is shipped within the package itself. If you want to use other data you have to download them and import them in your R session (use st_read() from the sf package to import geo data).
The best source for Municipalities is the ADMINEXPRESS product from IGN. https://geoservices.ign.fr/documentation/diffusion/telechargement-donnees-libres.html#admin-express
You may have to import the whole set of municipalities (36600) and then select the ones from Gironde.
Hi! many thanks for this wonderful package! referent the first inset figure, when I tried to replicate the chunk I noted some maybe small bugs.
In: mf_map(mtq_inset, add = T, col = “tomato”), the x must be mtq_target
the same in: mf_init(mtq_inset),
and: mf_label(mtq_inset, var = “LIBGEO”, col = “black”)
with those modifications I succedd to reproduce the figure.
As a fan of the sf and stars package, I am very delighted with this and I will continue to explore the options. Regards
Hi,
Nice catch! You are correct.
It should be ok now.
Thank you