I would like to change the font for the main title of a thematic plot using the tmap package in R from 'plain' to italics but keep the font for the legend heading and text 'plain'.
However, when I change the argument fontface in the lm_layout() function it changes the font face of all text in the map. Is it possible to only change the font face for the main title in tmap?
My attempt at a reproducible example (which, unfortunately, changes the font face of all text in the map to italics) is below:
library(tmap)
data("World")
tm_shape(World) +
tm_polygons("HPI", title = "World - HPI") +
tm_layout(main.title = "HPI",
main.title.position = "center",
fontface = 3)
Edit: Martijn Tennekes, the author of the tmap package, has added 10 arguments to tm_layout (and therefore also tmap options) to allow control over this: a local fontface and fontfamily for the (map) title, main title, panel.label, legend.title and legend.text.
tm <- tm_shape(World) +
tm_polygons(c("HPI", "economy"), title = c("Legend 1", "Legend 2")) +
tm_layout(main.title = "Main Title",
main.title.position = "center",
title = c("Title 1", "Title 2"),
panel.labels = c("Panel 1", "Panel 2"))
# global setting
tm + tm_layout(fontface = 3)
# local setting
tm + tm_layout(main.title.fontface = 1, title.fontface = 2, panel.label.fontface = 3, legend.text.fontface = 4, legend.title.fontfamily = "serif")
fontface
argument is global = it covers all text in the map. – Notationfontface
argument is global from reading the help documentation. Do you know if it is possible to only change the font to italics for themain.title
argument in tmap? I also tried usingexpression
terms in tmap to change the font style (for either themain.title
orlegend
), but had no luck. Thanks in advance for any advice to make this change – Twittgeom_sf()
in ggplot, which has pretty advanced formatting, or dynamic map via leaflet which allows HTML tags – Notationmain.title
is to label a species' scientific name, while 'plain' text seems more appropriate for legends. One hacky way I found to change the legend title to plain was to put 'expression' around a new title, e.g. expression("World - HPI"). Not sure how to change the remainder of the legend text to plain though – Twitttmap
- you may consider filing an issue github.com/mtennekes/tmap/issues - to have the option included in future releases – Notation