Learn R Programming

tmap (version 1.2)

tm_facets: Small multiples

Description

Creates a tmap-element that specifies how small multiples are placed in a facet grid. Either the argument by should be specified, i.e. the name of a variable by which the data is grouped, or multiple variable names sould be provided with tm_fill, tm_lines, or tm_bubbles. In this function, the number of rows and columns can be specified, as well as whether the scales are free (i.e. independent of each other).

Usage

tm_facets(by = NULL, ncol = NULL, nrow = NULL, free.coords = FALSE,
  drop.shapes = free.coords, free.scales = is.null(by),
  free.scales.fill = free.scales, free.scales.bubble.size = free.scales,
  free.scales.bubble.col = free.scales, free.scales.text.size = free.scales,
  free.scales.text.col = free.scales, free.scales.line.col = free.scales,
  free.scales.line.lwd = free.scales, free.scales.raster = free.scales,
  inside.original.bbox = FALSE, scale.factor = 2)

Arguments

by
data variable name by which the data is split
ncol
number of columns of the small multiples grid
nrow
number of rows of the small multiples grid
free.coords
logical. If the by argument is specified, should each map has its own coordinate ranges?
drop.shapes
logical. If the by argument is specified, should all non-selected shapes be dropped?
free.scales
logical. Should all scales of the plotted data variables be free, i.e. independent of each other? Possible data variables are color from tm_fill, color and size from
free.scales.fill
logical. Should the color scale for the choropleth be free?
free.scales.bubble.size
logical. Should the bubble size scale for the bubble map be free?
free.scales.bubble.col
logical. Should the color scale for the bubble map be free?
free.scales.text.size
logical. Should the text size scale be free?
free.scales.text.col
logical. Should the text color scale be free?
free.scales.line.col
Should the line color scale be free?
free.scales.line.lwd
Should the line width scale be free?
free.scales.raster
Should the color scale for raster layers be free?
inside.original.bbox
If free.coords, should the bounding box of each small multiple be inside the original bounding box?
scale.factor
Number that determines how the elements (e.g. font sizes, bubble sizes, line widths) of the small multiples are scaled in relation to the scaling factor of the shapes. The elements are scaled to the scale.factorth root of the scaling factor o

Value

See Also

../doc/tmap-nutshell.html{vignette("tmap-nutshell")}

Examples

Run this code
data(World, Europe, NLD_muni, NLD_prov)

# Facets defined by constant values
tm_shape(World) +
    tm_fill(c("forestgreen", "goldenrod")) +
tm_format_World(title=c("A green world", "A dry world"), bg.color="lightskyblue2", 
    title.position=c("left", "bottom"))

# Facets defined by multiple variables
tm_shape(Europe) +
    tm_borders() +
    tm_fill(c("gdp_cap_est", "pop_est_dens"), style="kmeans", 
        title=c("GDP per capita", "Population density")) +
tm_format_Europe()

tm_shape(NLD_muni) +
    tm_fill(c("pop_0_14", "pop_15_24", "pop_25_44", "pop_45_64", "pop_65plus"),
        style="kmeans", 
        palette=list("Oranges", "Greens", "Blues", "Purples", "Greys"),
        title=c("Population 0 to 14", "Population 15 to 24", "Population 25 to 44",
            "Population 45 to 64", "Population 65 and older")) +
tm_shape(NLD_prov) +
    tm_borders() +
tm_format_NLD(frame = TRUE, asp=0)

# Facets defined by groupings
tm_shape(NLD_prov) +
    tm_borders() +
    tm_fill("gold2") +
    tm_facets(by="name") +
    tm_layout()

tm_shape(NLD_prov) +
    tm_fill("gold2") + tm_borders() +
    tm_facets(by="name", free.coords = TRUE, drop.shapes=TRUE) +
tm_layout()

tm_shape(NLD_muni) +
    tm_borders() +
    tm_facets(by="province") +
    tm_fill("population", style="kmeans", convert2density = TRUE) +
tm_shape(NLD_prov) +
    tm_borders(lwd=4) +
    tm_facets(by="name", free.coords=TRUE, drop.shapes=TRUE) +
tm_layout(legend.show = FALSE)

Run the code above in your browser using DataLab