50% off | Unlimited Data & AI Learning
Get 50% off unlimited learning

tmap (version 0.6)

tm_text: Add text labels

Description

This layer adds text labels

Usage

tm_text(text, cex = 1, root = 3, fontcolor = NA, fontface = "plain",
  fontfamily = "sans", case = NA, bg.color = NA, bg.alpha = 100,
  cex.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
cex
relative size of the text labels. Eiter one number, a name of a numeric variable in the shape data that is used to scale the sizes proportionally, or AREA where the text size is proportional to the the area size of the polygons.
root
root number to which the font sizes are scaled. Only applicable if cex is a variable name or "AREA". If root=2, the square root is taken, if root=3 the cube root etc.
fontcolor
relative size of the text labels
fontface
font face of the text labels
fontfamily
font family of the text labels
case
case of the font. Use "upper" to generate upper-case text, "lower" to generate lower-case text, and use NA to leave the text as is.
bg.color
background color of the text labels. By default, bg.color=NA, so no background is drawn.
bg.alpha
number between 0 and 255 that specifies the transparancy of the text background (0 is totally transparent, 255 is solid background). The default value is 100.
cex.lowerbound
lowerbound for cex. Needed to ignore the tiny labels in case cex is a variable.
print.tiny
boolean that determines if tiny labels (which size is smaller than cex.lowerbound) are print at size cex.lowerbound
scale
scalar needed in case cex is based
xmod
horizontal position modification of the text, relatively where 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. Togeth
ymod
vertical position modification. See xmod.

Value

See Also

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

Examples

Run this code
# Europe example
data(Europe)
tm_shape(Europe) +
    tm_fill("gdp_cap_est", style="kmeans", textNA = "Non-European countries") +
    tm_borders() +
    tm_text("iso_a3", cex="AREA", scale=2, bg.alpha=0) +
tm_layout_Europe("GDP per capita")


data(rivers)
data(cities)

tm_shape(Europe) +
    tm_fill("pop_est_dens", style="kmeans", textNA="Non-European countries") +
    tm_borders() +
tm_shape(rivers) +
    tm_lines("dodgerblue3") +
tm_shape(cities) +
    tm_text("name", cex="pop_max", scale=1, ymod=-.02, root=4, cex.lowerbound = .60, 
            bg.color="yellow", bg.alpha = 150) + 
    tm_bubbles("pop_max", "red", border.col = "black", border.lwd=1, size.lim = c(0, 2e7)) +
tm_shape(Europe) +
    tm_text("name", cex="area", scale=1.5, root=8, cex.lowerbound = .40, 
            fontface="bold", case=NA, fontcolor = "gray35") + 
tm_layout_Europe("Map of Europe", 
    legend.titles = c(fill="Country population density (people per km2)", 
                      bubble.size="City Population"))

Run the code above in your browser using DataLab