Learn R Programming

tmap (version 1.2)

tm_layout: Layout of cartographic maps

Description

This element specifies the map layout. The main function tm_layout controlls title, margins, aspect ratio, colors, frame, legend, among many other things. The function tm_legend is a shortcut to access all legend. arguments without this prefix. The other functions are wrappers for two purposes: the tm_format_ functions specify position related layout settings such as margins, and the tm_style_ functions specify general styling related layout settings such as colors and font. Typically, the former functions are shape dependent, and the latter functions are shape independent. See details for predefined styles and formats. With the global option tmap.style, a default style can be specified. Multiple tm_layout elements (or wrapper functions) can be stacked: called arguments will be overwritten.

Usage

tm_layout(title = NA, scale = 1, title.size = 1.3, bg.color = "white",
  aes.color = c(fill = "grey85", borders = "grey40", bubbles = "blueviolet",
  dots = "black", lines = "red", text = "black", na = "grey70"),
  aes.palette = list(seq = "YlOrBr", div = "RdYlGn", cat = "Set3"),
  attr.color = "black", sepia.intensity = 0, saturation = 1,
  frame = TRUE, frame.lwd = 1, frame.double.line = FALSE, asp = NA,
  outer.margins = rep(0.02, 4), inner.margins = NA, outer.bg.color = NULL,
  fontface = "plain", fontfamily = "sans", compass.type = "arrow",
  earth.boundary = FALSE, earth.boundary.color = attr.color,
  earth.boundary.lwd = 1, earth.datum = "WGS84", space.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.format = list(scientific = FALSE, digits = NA, text.separator = "to",
  text.less.than = "Less than", text.or.more = "or more"),
  legend.frame = FALSE, legend.text.color = attr.color,
  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.color = attr.color,
  title.bg.color = NA, title.bg.alpha = 1, attr.position = c("right",
  "bottom"), design.mode = FALSE)

tm_legend(...)

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

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

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

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

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

tm_format_NLD_wide(title = NA, 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, attr.position = c("left", "bottom"), ...)

tm_style_white(...)

tm_style_gray(bg.color = "grey85", aes.color = c(fill = "grey70", borders =
  "grey20", bubbles = "blueviolet", dots = "black", lines = "red", text =
  "black", na = "grey60"), ...)

tm_style_natural(bg.color = "lightskyblue1", aes.color = c(fill =
  "darkolivegreen3", borders = "black", bubbles = "tomato2", dots = "firebrick",
  lines = "steelblue", text = "black", na = "white"), aes.palette = list(seq =
  "YlGn", div = "RdYlGn", cat = "Set3"), attr.color = "black",
  space.color = "white", earth.boundary = TRUE, ...)

tm_style_grey(bg.color = "grey85", aes.color = c(fill = "grey70", borders =
  "grey20", bubbles = "blueviolet", dots = "black", lines = "red", text =
  "black", na = "grey60"), ...)

tm_style_cobalt(bg.color = "#002240", aes.color = c(fill = "#0088FF",
  borders = "#002240", bubbles = "#FF9D00", dots = "#FF9D00", lines = "#FFEE80",
  text = "white", na = "grey60"), aes.palette = list(seq = "YlGn", div =
  "RdYlGn", cat = "Set3"), attr.color = "white", ...)

tm_style_col_blind(bg.color = "white", aes.color = c(fill = "grey85",
  borders = "black", bubbles = "#D55E00", dots = "#0072B2", lines = "#009E73",
  text = "black", na = "white"), aes.palette = list(seq = "Blues", div =
  "RdBu", cat = c("#D55E00", "#56B4E9", "#E69F00", "#009E73", "#F0E442",
  "#0072B2", "#CC79A7")), attr.color = "black", ...)

tm_style_albatross(bg.color = "#00007F", aes.color = c(fill = "#4C4C88",
  borders = "#00004C", bubbles = "#BFBFFF", dots = "#BFBFFF", lines = "#BFBFFF",
  text = "#FFE700", na = "grey60"), aes.palette = list(seq = "YlOrRd", div =
  "RdYlGn", cat = "Set3"), attr.color = "#BFBFFF", ...)

tm_style_beaver(bg.color = "#FFFFFF", aes.color = c(fill = "#FFE200",
  borders = "#000000", bubbles = "#A30000", dots = "#A30000", lines = "#A30000",
  text = "#000000", na = "#E0E0E0"), aes.palette = list(seq = "YlOrBr", div =
  "RdYlGn", cat = "Dark2"), attr.color = "black", ...)

tm_style_bw(saturation = 0, ...)

tm_style_classic(sepia.intensity = 0.7, fontfamily = "serif",
  frame.double.line = TRUE, compass.type = "rose", ...)

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").
aes.color
Default color values for the aesthetics layers. Should be a named vector with the names chosen from: fill, borders, bubbles, dots, lines, text, na.
aes.palette
Default color palettes for the aesthetics. It takes a list of three items: seq for sequential palettes, div for diverging palettes, and cat for categorical palettes. By default, Color Brewer palettes (see (see
attr.color
Default color value for map attributes
sepia.intensity
Number between 0 and 1 that defines the amount of sepia effect, which gives the map a brown/yellowish flavour. By default this effect is disabled (sepia.intensity=0). All colored used in the map are adjusted with this effect.
saturation
Number that determines how much saturation (also known as chroma) is used: saturation=0 is greyscale and saturation=1 is normal. A number larger than 1 results in very saturated maps. All colored used in the map are adjusted with
frame
Either a boolean that determines whether a frame is drawn, or a color value that specifies the color of the frame.
frame.lwd
width of the frame
frame.double.line
draw a double frame line border?
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
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. By default, 0 for each side if master shape is a raster, otherwise 0.02.
outer.bg.color
Background color outside the frame.
fontface
font face of all text in the map.
fontfamily
font family of the text labels.
compass.type
type of compass, one of: "arrow", "4star", "8star", "radar", "rose". Of course, only applicable if a compass is shown. The compass type can also be set within
earth.boundary
Logical that determines whether the boundaries of the earth are shown or an object that specifies the boundaries. This object can be a vector of size four, a 2 by 2 matrix (bounding box), or an extent<
earth.boundary.color
Color of the earth boundary.
earth.boundary.lwd
Line width of the earth boundary.
earth.datum
Geodetic datum to determine the earth boundary. By default "WGS84", other frequently used datums are "NAD83" and "NAD27". Any other PROJ.4 character string can be used.
space.color
Color of the space, i.e. the region inside the frame, and outsise the earth boundary.
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", "LEFT", "center", "right", or "RIGHT" for the first value and "top", "TOP", "center", "bottom", or "BOTTOM" for the second value, or this
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.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.format
list of formatting options for the legend numbers. Only applicable if labels is undefined. Parameters are: [object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
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. The width of the frame is automatically determined, but is upper-bounded by legend.width.
legend.text.color
color of the legend text
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", "LEFT", "center", "right", or "RIGHT" for the first value and "top", "TOP", "center", "bottom", or "BOTTOM" for the second value, or this v
title.color
color of the title
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).
attr.position
Position of the map attributes, which are tm_credits, tm_scale_bar and tm_compass. Vector of two
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

Details

Predefined styles: ll{ tm_style_white White background, commonly used colors (default) tm_style_grey/_grey Grey background, useful to highlight sequential palettes (e.g. in choropleths) tm_style_natural Emulation of natural view: blue waters and green land tm_style_bw Greyscale, obviously useful for greyscale printing tm_style_classic Classic styled maps (recommended) tm_style_cobalt Inspired by latex beamer style cobalt tm_style_albatross Inspired by latex beamer style cobalt tm_style_beaver Inspired by latex beamer style beaver --------------------------- --------------------------------------------------------------------------------------------------- } Predefined formats ll{ tm_format_World Format specified for world maps tm_format_World_wide Format specified for world maps with more space for the legend tm_format_Europe Format specified for maps of Europe tm_format_Europe_wide Format specified for maps of Europe with more space for the legend tm_format_NLD Format specified for maps of the Netherlands tm_format_NLD_wide Format specified for maps of the Netherlands with more space for the legend --------------------------- --------------------------------------------------------------------------------------------------- }

See Also

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

Examples

Run this code
data(World, land)

tm_shape(World) + 
    tm_fill("pop_est_dens", style="kmeans", title="Population density") +
tm_format_World(title="The World") + tm_style_albatross(frame.lwd=10)

land_eck4 <- set_projection(land, "eck4") # convert to Eckert IV projection

tm_shape(land_eck4) +
	tm_raster("elevation", breaks=c(-Inf, 250, 500, 1000, 1500, 2000, 2500, 3000, 4000, Inf),  
		palette = terrain.colors(9), title="Elevation", auto.palette.mapping = FALSE) +
tm_shape(World) +
	tm_borders("grey20") +
	tm_grid(projection="longlat", labels.size = .5) +
	tm_text("name", size="AREA") +
tm_compass(position = c(.65, .15), color.light = "grey90") +
tm_credits("Eckert IV projection", position = c("right", "BOTTOM")) +
tm_layout(inner.margins=c(.04,.03, .02, .01), 
	earth.boundary = TRUE, 
	space.color="grey90") +
tm_style_classic(bg.color="lightblue") +
tm_legend(position = c("left", "bottom"), 
	frame = TRUE,
	bg.color="lightblue")

WorldOne <- rgeos::gUnaryUnion(World)
tm_shape(World, projection="wintri") +
	tm_fill("HPI", palette="div", auto.palette.mapping = FALSE, n=7, 
			title = "Happy Planet Index") +
	tm_shape(WorldOne) + 
	tm_borders() +
	tm_grid(projection = "longlat") +
tm_credits("Winkel Tripel projection", position = c("right", "BOTTOM")) +
tm_style_natural(earth.boundary = c(-180,180,-87,87), inner.margins = .05) +
tm_legend(position=c("left", "bottom"), bg.color="grey95", frame=TRUE)

# the last three elements (tm_layout, tm_style_classic, and tm_legend)
# can also be merged into one element function:
tm_style_classic(inner.margins=c(.04,.03, .02, .01), 
	earth.boundary = TRUE, 
	space.color="grey90",
	bg.color="lightblue", 
	legend.position = c("left", "bottom"), 
	legend.frame = TRUE,
	legend.bg.color="lightblue")

# global option tmap.style:
qtm(World, fill="economy", format="World")
options(tmap.style = "col_blind")
qtm(World, fill="economy", format="World")
options(tmap.style = "cobalt")
qtm(World, fill="economy", format="World")
options(tmap.style = "white") # the default

Run the code above in your browser using DataLab