New release of mapsf: version 1.0.0

mapsf
Author

Timothée Giraud

Published

July 1, 2025

The first major version of mapsf has been deployed on CRAN!

The mapsf R package package helps you make different kinds of maps, like proportional symbols, choropleths, or typology maps. It also provides several functions for displaying layout elements that enhance the graphical presentation of maps (e.g., scale bar, north arrow, title, or labels).

This post will show you some of the new features of the package:

The dataset used in the following examples is about apartment rental prices in 2023 (source).
Download the dataset:

Revamped theming system

A new theming system has been introduced. This has led to new default values and a new default map style.
This new version lets you change more settings for the graphics, like choosing the default color palettes or using three colors instead of two. mf_theme() sets the map theme, a set of graphical parameters that are applied to maps created with mapsf. These settings include background, foreground, and highlight colors; margin sizes; frames; as well as default sequential and qualitative palettes. They also include title options, such as position, size, and banner settings.
Themes are persistent across maps produced by mapsf (e.g. they survive a dev.off() call).

The default theme

The default theme is called “base”.

library(mapsf)
com <- sf::st_read("com.gpkg", quiet = TRUE)
mf_theme("base")
mf_map(com)
mf_title("New default theme")
mf_scale()
mf_credits()
mf_arrow()

Builtin themes

mapsf has some themes already included. You can modify an existing theme or start a new one. If you want to have a look at the 8 builtin themes you can go to the vignette about themes on mapsf website.

mf_theme("sol_light")
mf_map(com, 'loypredm2', 'choro', breaks = "ckmeans", nbreaks = 4)
mf_title('sol_light theme')
mf_theme("sol_light", highlight = "brown", title_banner = TRUE, pal_seq = "Teal")
mf_map(com, 'loypredm2', 'choro', breaks = "ckmeans", nbreaks = 4)
mf_title('Modified sol_light theme')

Improved display of map elements

In this new version, map elements are redrawn when the graphic device is resized. This behavior is a great improvement for interactive map displays, especially when using RStudio or Positron.

Previous release

Current release

Updated Cheat Sheet

We’ve updated the cheat sheet to reflect the changes made to the package.
Get the PDF file of the cheat sheet:

Export to SVG and PNG file format

mf_svg() and mf_png() functions export maps in SVG and PNG formats, respectively. These two functions replace mf_export().

SVG export is the perfect solution for editing maps with desktop vector graphics software, such as Inkscape. SVG is a vector graphics file format.
The default driver for building SVG files, grDevices::svg(), has limitations regarding speed, file size, editability, and font support. The svglite package aims to solve these issues. However, the svglite package is not lightweight in terms of dependencies, so it is not imported by mapsf, but rather suggested. However, we strongly recommend using it if you plan to edit the maps after exporting them.

PNG export should be used for maps that do not require further modification. PNG is a raster graphics file format.

The width-to-height ratio of the exported map matches that of a spatial object. If width is specified, then height is deduced from the width-to-height ratio of x. Alternatively, if height is specified, then width is deduced from the width-to-height ratio of x. This helps to produce maps without too much wasted space.

You can find some examples of use in the vignette about exports on mapsf website.

Designing diverging color palettes

The mf_get_pal() function has been updated to make it simpler to create diverging color palettes based on a vector of break values.

In the following examples, we use a classification method based on the mean and the standard deviation of a distribution. Using this method the mean value can be a class boundary (example 1) or a class center (example 2).

Use a class boundary

The first step is to create the vector of break values. We use central = FALSE to have the mean as a break value. Then we use mf_get_pal() with the breaks vector, the mean value and 2 color palette names to create the corresponding diverging color palette.

bks_1 <- mf_get_breaks(x = com$loypredm2, breaks = "msd", central = FALSE)
pal_1 <- mf_get_pal(breaks = bks_1, mid = mean(com$loypredm2), 
                    palette = c("Burg", "Teal"))
mf_map(com, "loypredm2", "choro", breaks = bks_1, pal = pal_1)
mf_title("Diverging color palette", cex = 1)

Use a class center (or any value)

In this second example, we use the same method, but we use a central class (central = TRUE). The resulting palette includes a neutral color for the central class that contains the mean value.

bks_2 <- mf_get_breaks(x = com$loypredm2, breaks = "msd", central = TRUE)
pal_2 <- mf_get_pal(breaks = bks_2, mid = mean(com$loypredm2), 
                    palette = c("Burg", "Teal"))
mf_map(com, "loypredm2", "choro", breaks = bks_2, pal = pal_2)
mf_title("Diverging color palette with a neutral color", cex = 1)

Breaking changes

Withdrawal of deprecated functions and arguments

All previously deprecated functions and arguments have been withdrawn from the package. The complete list of removed functions and arguments is available in the changelog.

New theme

The new theme system uses new default values for colors, margins and other graphical parameters, so the default map produced with mapsf will not look the same.
If you need to use the old (pre v1.0.0) default theme, use the “default” theme:

mf_theme(x = "default")
mf_map(com)
mf_title("Former default theme")
mf_scale()
mf_credits()
mf_arrow()

Note that mf_theme() arguments names have changed. “bg”, “fg”, “tab”, “pos”, “inner”, “line”, “cex” and “font” are deprecated arguments.
If old (deprecated) arguments are used, new ones are totally ignored and we try to keep the old theme behavior.

Mapping points

When plotting a base layer of points with pch set to a value between 21 and 25, we now use col for fill color and border for contour color whereas previous versions used bg for fill color and col for contour color.


See the NEWS file for the complete list of changes.