Add text labels
tmap-element that adds text labels.
tm_text(text, size = 1, col = NA, root = 3, size.lim = NA, sizes.legend = NULL, sizes.legend.labels = NULL, sizes.legend.text = "Abc", n = 5, style = ifelse(is.null(breaks), "pretty", "fixed"), breaks = NULL, interval.closure = "left", palette = NULL, labels = NULL, labels.text = NA, auto.palette.mapping = TRUE, contrast = NA, max.categories = 12, colorNA = NA, textNA = "Missing", showNA = NA, fontface = NA, fontfamily = NA, alpha = NA, case = NA, shadow = FALSE, bg.color = NA, bg.alpha = NA, size.lowerbound = 0.4, print.tiny = FALSE, scale = 1, auto.placement = FALSE, remove.overlap = FALSE, along.lines = FALSE, overwrite.lines = FALSE, just = c("center", "center"), xmod = 0, ymod = 0, title.size = NA, title.col = NA, legend.size.show = TRUE, legend.col.show = TRUE, legend.format = list(), legend.size.is.portrait = FALSE, legend.col.is.portrait = TRUE, legend.hist = FALSE, legend.hist.title = NA, legend.size.z = NA, legend.col.z = NA, legend.hist.z = NA)
- name of the variable in the shape object that contains the text labels
- 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 polygons.
- color of the text labels. Either a color value or a data variable name. If multiple values are specified, small multiples are drawn (see details).
- root number to which the font sizes are scaled. Only applicable if
sizeis a variable name or
root=2, the square root is taken, if
root=3, the cube root etc.
- vector of two limit values of the
sizevariable. Only text labels are drawn whose value is greater than or equal to the first value. Text labels whose values exceed the second value are drawn at the size of the second value. Only applicable when
sizeis the name of a numeric variable of
shp. See also
size.lowerboundwhich is a threshold of the relative font size.
- vector of text sizes that are shown in the legend. By default, this is determined automatically.
- vector of labels for that correspond to
- vector of example text to show in the legend next to sizes.legend.labels. By default "Abc". When
NA, examples from the data variable whose sizes are close to the sizes.legend are taken and
"NA"for classes where no match is found.
- preferred number of color scale classes. Only applicable when
colis a numeric variable name.
- method to process the color scale when
colis a numeric variable. Discrete options are
"jenks". A numeric variable is processed as a categorial variable when using
"cat", i.e. each unique value will correspond to a distinct category. For the other discrete options, see the details in
classIntervals. Continuous options are
"order". The former maps the values of
colto a smooth gradient, whereas the latter maps the order of values of
colto a smooth gradient. They are the continuous variants of respectively the discrete methods "equal" and quantile".
- in case
style=="fixed", breaks should be specified. The
breaksargument can also be used when
style="cont". In that case, the breaks are mapped evenly to the sequential or divering color palette.
- value that determines whether where the intervals are closed:
"right". Only applicable if
colis a numerc variable.
- a palette name or a vector of colors. See
tmaptools::palette_explorer()for the named palettes. Use a
"-"as prefix to reverse the palette. The default palette is taken from
aes.palette, which typically depends on the style. The type of palette from
aes.paletteis automatically determined, but can be overwritten: use
"div"for diverging, and
- labels of the color classes, applicable if
colis a data variable name
- Example text to show in the legend next to the
NA(default), examples from the data variable are taken and
"NA"for classes where they don't exist.
- When diverging colour palettes are used (i.e. "RdBu") this method automatically maps colors to values such that the middle colors (mostly white or yellow) are assigned to values of 0, and the two sides of the color palette are assigned to negative respectively positive values. When categorical color palettes are used, this method stretches the palette if there are more levels than colors.
- vector of two numbers that determine the range that is used for sequential and diverging palettes (applicable when
auto.palette.mapping=TRUE). Both numbers should be between 0 and 1. The first number determines where the palette begins, and the second number where it ends. For sequential palettes, 0 means the brightest color, and 1 the darkest color. For diverging palettes, 0 means the middle color, and 1 both extremes. If only one number is provided, this number is interpreted as the endpoint (with 0 taken as the start).
- in case
colis the name of a categorical variable, this value determines how many categories (levels) it can have maximally. If the number of levels is higher than
FALSE, then levels are combined.
- colour for missing values. Use
- text used for missing values.
- logical that determines whether missing values are named in the legend. By default (
NA), this depends on the presence of missing values.
- font face of the text labels. By default, determined by the fontface argument of
- font family of the text labels. By default, determined by the fontfamily argument of
- transparency number between 0 (totally transparent) and 1 (not transparent). By default, the alpha value of the
fontcoloris used (normally 1).
- case of the font. Use "upper" to generate upper-case text, "lower" to generate lower-case text, and
NAto leave the text as is.
- logical that determines whether a shadow is depicted behind the text. The color of the shadow is either white or yellow, depending of the
- background color of the text labels. By default,
bg.color=NA, so no background is drawn.
- number between 0 and 1 that specifies the transparancy of the text background (0 is totally transparent, 1 is solid background).
- lowerbound for
size. Only applicable when
sizeis not a constant. If
TRUE, then all text labels which relative text is smaller than
size.lowerboundare depicted at relative size
FALSE, then text labels are only depicted if their relative sizes are at least
size.lowerbound(in other words, tiny labels are omitted).
- boolean, see
- text size multiplier, useful in case
sizeis variable or
- logical (or numeric) that determines whether the labels are placed automatically. If
TRUE, the labels are placed next to the coordinate points with as little overlap as possible using the simulated annealing algorithm. Therefore, it is recommended for labeling spatial dots or symbols. If a numeric value is provided, this value acts as a parameter that specifies the distance between the coordinate points and the text labels in terms of text line heights.
- logical that determines whether the overlapping labels are removed
- logical that determines whether labels are rotated along the spatial lines. Only applicabel if a spatial lines shape is used.
- logical that determines whether the part of the lines below the text labels is removed. Only applicabel if a spatial lines shape is used.
- justification of the text relative to the point coordinates. The first value specifies horizontal and the second value vertical justification. Possible values are:
"top". Numeric values of 0 specify left alignment and 1 right alignment.
- horizontal position modification of the text (relatively): 0 means no modification, and 1 corresponds to the height of one line of text. Either a single number for all polygons, or a numeric variable in the shape data specifying a number for each polygon. Together with
ymod, it determines position modification of the text labels. In most coordinate systems (projections), the origin is located at the bottom left, so negative
xmodmove the text to the left, and negative
ymodvalues to the bottom.
- vertical position modification. See xmod.
- title of the legend element regarding the text sizes
- title of the legend element regarding the text colors
- logical that determines whether the legend for the text sizes is shown
- logical that determines whether the legend for the text colors is shown
- list of formatting options for the legend numbers. Only applicable if
labelsis undefined. Parameters are:
- Function to specify the labels. It should take a numeric vector, and should return a character vector of the same size. By default it is not specified. If specified, the list items
digits(see below) are not used.
- Should the labels be formatted scientically? If so, square brackets are used, and the
formatof the numbers is
text.or.moreare used. Also, the numbers are automatically rounded to millions or billions if applicable.
- By default,
"f", i.e. the standard notation
xxx.xxx, is used. If
"g", which means that numbers are formatted scientically, i.e.
n.dddE+nnif needed to save space.
- Number of digits after the decimal point if
format="f", and the number of significant digits otherwise.
- Character string to use to separate numbers in the legend (default: "to").
- Character string to use to translate "Less than" (which is the default).
- Character string to use to translate "or more" (which is the default).
- Other arguments passed on to
- logical that determines whether the legend element regarding the text sizes is in portrait mode (
TRUE) or landscape (
- logical that determines whether the legend element regarding the text colors is in portrait mode (
TRUE) or landscape (
- logical that determines whether a histogram is shown regarding the text colors
- title for the histogram. By default, one title is used for both the histogram and the normal legend for text colors.
- index value that determines the position of the legend element regarding the text sizes with respect to other legend elements. The legend elements are stacked according to their z values. The legend element with the lowest z value is placed on top.
- index value that determines the position of the legend element regarding the text colors. (See
- index value that determines the position of the histogram legend element. (See
The absolute fontsize (in points) is determined by the (ROOT) viewport, which may depend on the graphics device.
current.mode <- tmap_mode("plot") data(World, Europe, metro) tm_shape(World) + tm_text("name", size="AREA") tm_shape(Europe) + tm_polygons() + tm_text("iso_a3", size="AREA", col = "grey20", root=4, shadow = TRUE, scale=2, size.lowerbound = .1) + tm_shape(Europe) + tm_text("name", size="AREA", root=4, scale=1, ymod=-1 * tmaptools::approx_areas(Europe, target = "norm")^(1/4)) tm_shape(Europe) + tm_polygons() + tm_shape(metro) + tm_bubbles("pop2010", size.lim = c(0, 15e6), title.size = "European metropolitan areas") + tm_shape(metro[metro$pop2010>=2e6, ]) + tm_text("name", auto.placement = TRUE) + tm_format_Europe() tm_shape(World) + tm_text("name", size="pop_est", col="continent", palette="Dark2", title.size = "Population", title.col="Continent") + tm_legend(outside = TRUE) # restore current mode tmap_mode(current.mode)
Looks like there are no examples yet.