Learn R Programming

tmap (version 1.0)

tm_layout: Layout elements of cartographic maps

Description

This element specifies layout options for the maps. The main function tm_layout can be seen as a general layout theme. The functions tm_layout_World, tm_layout_Europe, and tm_layout_NLD are layout themes specified for the world, Europe, and Netherlands maps (which are contained in this package). For each of these layout themes, there is also an extra wide variant, with more space for the legend. Tip: create a layout theme for your own map (see example below).

Usage

tm_layout(title = NA, scale = 1, title.size = 1.3, bg.color = NULL,
  draw.frame = TRUE, asp = NA, frame.lwd = 1, outer.margins = rep(0.02,
  4), inner.margins = rep(0.02, 4), outer.bg.color = NULL,
  legend.show = TRUE, legend.only = FALSE, legend.position = NULL,
  legend.width = 0.3, legend.height = 0.9, legend.hist.height = 0.3,
  legend.hist.width = legend.width, legend.title.size = 1.1,
  legend.text.size = 0.7, legend.hist.size = 0.7,
  legend.scientific = FALSE, legend.digits = NA, legend.frame = FALSE,
  legend.bg.color = NA, legend.bg.alpha = 1, legend.hist.bg.color = NA,
  legend.hist.bg.alpha = 1, title.snap.to.legend = FALSE,
  title.position = c("left", "top"), title.bg.color = NA,
  title.bg.alpha = 1, design.mode = FALSE)

tm_layout_World(title = NA, inner.margins = c(0, 0.05, 0.025, 0.01),
  legend.position = c("left", "bottom"), scale = 0.8, ...)

tm_layout_World_wide(title = NA, inner.margins = c(0, 0.2, 0.025, 0.01),
  legend.position = c("left", "bottom"), legend.width = 0.4, scale = 0.8,
  ...)

tm_layout_Europe(title = NA, title.position = c("left", "top"),
  legend.position = c("left", "top"), inner.margins = c(0, 0.1, 0, 0), ...)

tm_layout_Europe_wide(title = NA, title.position = c("left", "top"),
  legend.position = c("left", "top"), inner.margins = c(0, 0.25, 0, 0),
  legend.width = 0.4, legend.hist.width = 0.4, ...)

tm_layout_NLD(title = NA, draw.frame = FALSE, inner.margins = c(0.02, 0.2,
  0.06, 0.02), legend.position = c("left", "top"), legend.width = 0.4, ...)

tm_layout_NLD_wide(title = NA, draw.frame = FALSE, inner.margins = c(0.02,
  0.3, 0.06, 0.02), legend.position = c("left", "top"), legend.width = 0.5,
  legend.hist.width = 0.35, ...)

Arguments

title
Title(s). By default, the name of the statistical variable of which the legend is drawn at the top (see legend.config) is used as a title.
scale
numeric value that serves as the global scale parameter. All font sizes, bubble sizes, border widths, and line widths are controled by this value. Each of these elements can be scaled independantly with the scale, lwd, or s
title.size
Relative size of the title
bg.color
Background color. By default it is "white". A recommended alternative for choropleths is light grey (e.g., "grey85").
draw.frame
Boolean that determines whether a frama is drawn.
asp
Aspect ratio. The aspect ratio of the map (width/height). If NA, it is determined by the bounding box (see argument bbox of tm_shape), the outer.margins, and the
frame.lwd
Width of the frame
outer.margins
Relative margins between device and frame. Vector of four values specifying the bottom, left, top, and right margin. Values are between 0 and 1.
inner.margins
Relative margins inside the frame. Vector of four values specifying the bottom, left, top, and right margin. Values are between 0 and 1.
outer.bg.color
Background color outside the frame.
legend.show
Logical that determines whether the legend is shown.
legend.only
logical. Only draw the legend (without map)? Particularly useful for small multiples with a common legend.
legend.position
Position of the legend. Vector of two values, specifing the x and y coordinates. Either this vector contains "left", "center" or "right" for the first value and "top", "center", or "bottom" for the second value, or this vector contains two numeric values
legend.width
width of the legend
legend.height
maximum height of the legend.
legend.hist.height
height of the histogram. This hight is initial. If the total legend is downscaled to legend.height, the histogram is downscaled as well.
legend.hist.width
width of the histogram. By default, it is equal to the legend.width.
legend.title.size
Relative font size for the legend title
legend.text.size
Relative font size for the legend text elements
legend.hist.size
Relative font size for the choropleth histogram
legend.scientific
logical. Should the numeric legend labels be formatted scientific?
legend.digits
Number of digits for the legend labels
legend.frame
either a logical that determines whether the legend is placed inside a frame, or a color that directly specifies the frame border color.
legend.bg.color
Background color of the legend. Use TRUE to match with the overall background color bg.color.
legend.bg.alpha
Transparency number between 0 (totally transparent) and 1 (not transparent). By default, the alpha value of the legend.bg.color is used (normally 1).
legend.hist.bg.color
Background color of the histogram
legend.hist.bg.alpha
Transparency number between 0 (totally transparent) and 1 (not transparent). By default, the alpha value of the legend.hist.bg.color is used (normally 1).
title.snap.to.legend
Logical that determines whether the title is part of the legend.
title.position
Position of the title. Vector of two values, specifing the x and y coordinates. Either this vector contains "left", "center" or "right" for the first value and "top", "center", or "bottom" for the second value, or this vector contains two numeric values b
title.bg.color
background color of the title. Use TRUE to match with the overall background color bg.color.
title.bg.alpha
Transparency number between 0 (totally transparent) and 1 (not transparent). By default, the alpha value of the title.bg.color is used (normally 1).
design.mode
Logical that enables the design mode. If TRUE, inner and outer margins, legend position, aspect ratio are explicitely shown. Also, feedback text in the console is given.
...
other arguments from tm_layout

See Also

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

Examples

Run this code
data(World)

tm_shape(World) + 
    tm_fill("pop_est_dens", style="kmeans", title="Population density") + 
tm_layout_World("World Population", bg.color="lightblue")

# A custom layout wrapper for Africa
tm_layout_Africa <- function(title=NA,
							 inner.margins = c(.02, .25, .02, .02),
							 draw.frame = FALSE,
							 title.position=c("left", "bottom"), 
							 legend.position = c("left", "bottom"),
							 legend.width = 0.5,
							 bg.color = "lightskyblue2", ...) {
	args <- c(as.list(environment()), list(...))
	do.call("tm_layout", args)
}

Africa <- World[World$continent=="Africa", ]

qtm(Africa, fill="pop_est_dens", fill.style="kmeans", fill.title="Population density") + 
    tm_layout_Africa("Africa")

Run the code above in your browser using DataLab