Consider the following example:
library(tmap)
mydf <- NLD_muni %>% filter(province %in% c("Drenthe", "Flevoland"))
tm_shape(mydf) +
tm_polygons(
fill = c("employment_rate", "dwelling_value")) +
tm_facets_grid(columns = "province") +
tm_layout(
panel.labels = c("Employment Rate", "Dwelling Value"),
legend.show = FALSE
)

How can I insert labels for left and right columns on top of the plot?
For example I would like to label them "province 1" and "province 2".
Not sure if this is exactly what you're looking for, but my preference is always to just create all the necessary labels in the dataframe ahead of plotting. In that vein, this solution does what you're aiming for:
library(tmap)
library(dplyr)
mydf <- NLD_muni %>%
filter(province %in% c("Drenthe", "Flevoland")) %>%
mutate(
province_label = case_when(
province == "Drenthe" ~ "province 1",
province == "Flevoland" ~ "province 2"
)
) |>
rename(
"Employment Rate" = employment_rate,
"Dwelling Value" = dwelling_value
)
tm_shape(mydf) +
tm_polygons(
fill = c("Employment Rate", "Dwelling Value")
) +
tm_facets_grid(columns = "province_label") +
tm_layout(legend.show = FALSE)

It seems that overriding the default panel labels with the panel.labels argument is what caused the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With