Learn R Programming

tmap (version 0.7)

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). Tip: create a layout theme for your own map (see example below).

Usage

tm_layout(title = NA, scale = 1, title.cex = 1.5, bg.color = NULL,
  draw.frame = TRUE, title.position = NULL, title.bg.color = NA,
  asp = NA, frame.lwd = 1, outer.margins = rep(0.02, 4),
  inner.margins = rep(0.02, 4), outer.bg.color = "white",
  legend.show = TRUE, legend.hist.show = FALSE, legend.only = FALSE,
  legend.titles = c(fill = NA, bubble.size = NA, bubble.col = NA, line.col =
  NA, line.lwd = NA), legend.position = NULL, legend.is.portrait = c(fill =
  TRUE, bubble.size = FALSE, bubble.col = TRUE, line.col = TRUE, line.lwd =
  FALSE), legend.width = 0.3, legend.height = 0.9,
  legend.hist.height = 0.3, legend.config = c("fill_hist", "fill",
  "bubble.size", "bubble.col", "line.col", "line.lwd"), legend.title.cex = 1,
  legend.text.cex = 0.7, legend.hist.cex = 0.7, legend.scientific = FALSE,
  legend.digits = NA, legend.bg.color = NA)

tm_layout_World(title = NA, scale = 0.85, title.bg.color = TRUE,
  inner.margins = c(0, 0.02, 0.02, 0.02), legend.position = c("left",
  "bottom"), legend.width = 0.25, legend.height = 0.5,
  legend.bg.color = TRUE, ...)

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

tm_layout_NLD(title = NA, draw.frame = FALSE, inner.margins = c(0.05, 0.3,
  0.1, 0.05), legend.position = c("left", "top"), legend.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 c
title.cex
Relative size of the title
bg.color
Background color. By default it is light grey (grey85) for choropleths and white for other maps.
draw.frame
Boolean that determines whether a frama is drawn.
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.
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) and the argument frame.margins.
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. Use legend.config to configure which legend elements are shown.
legend.hist.show
Logical that determines whether to show a histogram for the choropleth fill variable.
legend.only
logical. Only draw the legend (without map)? Particularly useful for small multiples with a common legend.
legend.titles
titles of the legend elements. Named character vector, where the names correspond to the legend elements and the value to the titles of those elements. Possible legend element names are: "fill", "bubble.size", "bubble.col"<
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.is.portrait
logical vector that determines whether the orientation of the legend elements are portrait (TRUE) or landscape (FALSE). The vector should be named with the corresponding elements, which are "fill", "bubble.size
legend.width
maximum 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.config
character vector that specifies which legend elements are drawn and at what position. The legend elements are called "fill", "fill_hist", "bubble.size", "bubble.col", "line.col", and "
legend.title.cex
Relative font size for the legend title
legend.text.cex
Relative font size for the legend text elements
legend.hist.cex
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.bg.color
Background color of the legend. Use TRUE to match with the overall background color bg.color.
...
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") + 
	tm_layout_World("World Population")

# A custom layout wrapper for Africa
tm_layout_Africa <- function(title=NA,
							 inner.margins = c(.02, .4, .02, .02),
							 draw.frame = FALSE,
							 title.position=c("left", "bottom"), 
							 legend.position = c("left", "bottom"), 
							 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") + 
	tm_layout_Africa("Population of Africa")

Run the code above in your browser using DataLab