Learn R Programming

tmap (version 1.0)

tm_text: Add text labels

Description

Creates a tmap-element that adds text labels.

Usage

tm_text(text, size = 1, root = 3, fontcolor = NA, fontface = "plain",
  fontfamily = "sans", alpha = NA, case = NA, shadow = FALSE,
  bg.color = NA, bg.alpha = NA, size.lowerbound = 0.4,
  print.tiny = FALSE, scale = 1, xmod = 0, ymod = 0)

Arguments

text
name of the variable in the shape object that contains the text labels
size
relative size of the text labels (see note). Eiter one number, a name of a numeric variable in the shape data that is used to scale the sizes proportionally, or the value "AREA", where the text size is proportional to the area size of the pol
root
root number to which the font sizes are scaled. Only applicable if size is a variable name or "AREA". If root=2, the square root is taken, if root=3, the cube root etc.
fontcolor
color of the text labels
fontface
font face of the text labels
fontfamily
font family of the text labels
alpha
transparency number between 0 (totally transparent) and 1 (not transparent). By default, the alpha value of the fontcolor is used (normally 1).
case
case of the font. Use "upper" to generate upper-case text, "lower" to generate lower-case text, and NA to leave the text as is.
shadow
logical that determines whether a shadow is depicted behind the text. The color of the shadow is either white or yellow, depending of the fontcolor.
bg.color
background color of the text labels. By default, bg.color=NA, so no background is drawn.
bg.alpha
number between 0 and 1 that specifies the transparancy of the text background (0 is totally transparent, 1 is solid background).
size.lowerbound
lowerbound for size. Only useful when size is not a constant. If print.tiny is TRUE, then all text labels which relative text is smaller than size.lowerbound are depicted at relative size
print.tiny
boolean, see size.lowerbound
scale
text size multiplier, useful in case size is variable or "AREA".
xmod
horizontal position modification of the text (relatively): 0 means no modification, and 1 means the total width of the frame. Either a single number for all polygons, or a numeric variable in the shape data specifying a number for each polygon. Together w
ymod
vertical position modification. See xmod.

Value

See Also

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

Examples

Run this code
# World example
data(World)
tm_shape(World) +
    tm_text("name", size="AREA")

# Europe example
data(Europe)
tm_shape(Europe) +
    tm_polygons() +
    tm_text("iso_a3", size="AREA", root=4, shadow = TRUE, fontcolor = "grey20", scale=2,
        size.lowerbound = .1) +
tm_shape(Europe) +
    tm_text("name", size="AREA", root=4, scale=1,
        ymod=-.04 * approx_areas(Europe, unit = "norm")^(1/4))

Run the code above in your browser using DataLab