14  Charts

Table 14.1: Available chart types.
Function Description
tm_chart_histogram() Histogram
tm_chart_box() Box plot
tm_chart_violin() Violin plot
tm_chart_bar() Bar chart
tm_chart_donut() Donut chart
tm_chart_heatmap() Heatmap
tm_chart_none() No chart
library(tmap)
library(sf)
slo_regions = read_sf("data/slovenia/slo_regions.gpkg")
tm_shape(slo_regions) +
  tm_polygons(fill = "pop_dens")

tm_shape(slo_regions) +
  tm_polygons(fill = "pop_dens",
              fill.chart = tm_chart_histogram())

14.1 Numerical data

tm_shape(slo_regions) +
  tm_polygons(fill = "pop_dens",
              fill.chart = tm_chart_box())

tm_shape(slo_regions) +
  tm_polygons(fill = "pop_dens",
              fill.chart = tm_chart_violin())

tm_shape(slo_regions) +
  tm_polygons(fill = "pop_dens",
              fill.chart = tm_chart_donut())

14.2 Categorical data

tm_shape(slo_regions) +
  tm_polygons(fill = "region_group",
              fill.chart = tm_chart_bar())

tm_shape(slo_regions) +
  tm_polygons(fill = "region_group",
              fill.chart = tm_chart_donut())

14.3 Bivariate data

tm_shape(slo_regions) +
  tm_polygons(fill = tm_vars(c("pop_dens", "pop65perc"), multivariate = TRUE),
              fill.scale = tm_scale_bivariate(values = "purplegold"),
              fill.chart = tm_chart_heatmap())
#> Labels abbreviated by the first two letters, e.g.: "20 to 21" => "20"

14.4 Additional customization

tm_shape(slo_regions) +
  tm_polygons(fill = "pop_dens",
              fill.chart = tm_chart_histogram(
                extra.ggplot2 = ggplot2::theme_dark()
              ))

tm_shape(slo_regions) +
  tm_polygons(fill = "pop_dens",
              fill.chart = tm_chart_histogram())