Skip to contents

mf_theme() sets a map theme. A theme is a set of graphical parameters that are applied to maps created with mapsf.
These parameters are:

  • figure margins and frames,
  • background, foreground and highlight colors,
  • default sequential and qualitative palettes,
  • title options (position, size, banner…).

mapsf offers some builtin themes. It’s possible to modify an existing theme or to start a theme from scratch. Themes are persistent across maps produced by mapsf (e.g. they survive a dev.off() call).

Builtin themes

Here are the builtin themes.

proportional symbols map with base theme choropleth map with base theme
proportional symbols map with sol_dark theme choropleth map with sol_dark theme
proportional symbols map with sol_light theme choropleth map with sol_light theme
proportional symbols map with grey theme choropleth map with grey theme
proportional symbols map with mint theme choropleth map with mint theme
proportional symbols map with pistachio theme choropleth map with pistachio theme
proportional symbols map with dracula theme choropleth map with dracula theme
proportional symbols map with rzine theme choropleth map with rzine theme

How to modify an existing theme

It is possible to modify an existing theme. In this example we use the “base” theme and modify some title parameters.

library(mapsf)
mtq <- mf_get_mtq()
mf_theme("base", title_banner = TRUE, title_font = 4)
mf_map(mtq)
mf_title('Mofified "default" theme')

Map with a midified theme

How to create a new theme

It is possible to create a new theme from scratch.

mf_theme(
  mar          = c(0.1, 0.1, 1.85, 0.1),
  title_tab    = FALSE,
  title_pos    = "left",
  title_inner  = FALSE,
  title_line   = 1.75,
  title_cex    = 1.25,
  title_font   = 4,
  title_banner = FALSE,
  foreground   = "#F1F0E9",
  background   = "white",
  highlight    = "#E9762B",
  frame        = "map",
  frame_lwd    = 4,
  pal_quali    = "Dark 3",
  pal_seq      = colorRampPalette(c("#F1F0E9", "#41644A", "#0D4715"))
)
mf_map(mtq, "MED", "choro")
mf_title("New theme")

Map with a custom theme

It is also possible to assign a theme to a variable.

blue_theme <- mf_theme("base", background = "lightblue")
green_theme <- mf_theme("base", background = "lightgreen")
mf_theme(blue_theme)
mf_map(mtq)
mf_title("Blue Theme")

map with a blue theme

mf_theme(green_theme)
mf_map(mtq)
mf_title("Green Theme")

map with a green theme

Legacy themes

Although the map theming system has been radically changed in version 1.0.0 of the package, you can still use the old themes by referencing them by name.

mf_theme("default")
#> The following themes are deprecated:
#> 'default', 'brutal', 'ink', 'dark', 'agolalight', 'candy', 'darkula',
#> 'iceberg', 'green', 'nevermind', 'jsk', and 'barcelona'.
#> See the Note section in the help page (?mf_theme).
mf_map(mtq)
mf_title("Legacy default theme")

map with a legacy theme