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, 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, id = NA)
"AREA"
, where the text size is proportional to the area size of the polygons.size
is a variable name or "AREA"
. If root=2
, the square root is taken, if root=3
, the cube root etc.size
variable. 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 size
is the name of a numeric variable of shp
. See also size.lowerbound
which is a threshold of the relative font size.sizes.legend
.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.col
is a numeric variable name.col
is a numeric variable. Discrete options are "cat"
, "fixed"
, "sd"
, "equal"
, "pretty"
, "quantile"
, "kmeans"
, "hclust"
, "bclust"
, "fisher"
, and "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 "cont" and "order". The former maps the values of col
to a smooth gradient, whereas the latter maps the order of values of col
to a smooth gradient. They are the continuous variants of respectively the discrete methods "equal" and quantile".style=="fixed"
, breaks should be specifiedRColorBrewer::display.brewer.all
) for the text. Only when col
is set to a variable. The default palette is taken from tm_layout
's argument aes.palette
.col
is a data variable namelabels
. When NA
(default), examples from the data variable are taken and "NA"
for classes where they don't exist.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).col
is 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 max.categories
and auto.palette.mapping
is FALSE
, then levels are combined.NULL
for transparency.NA
), this depends on the presence of missing values.tm_layout
.tm_layout
.fontcolor
is used (normally 1).NA
to leave the text as is.fontcolor
.bg.color=NA
, so no background is drawn.size
. Only applicable 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 size.lowerbound
. If print.tiny
is FALSE
, then text labels are only depicted if their relative sizes are at least size.lowerbound
(in other words, tiny labels are omitted).size.lowerbound
size
is variable or "AREA"
.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 bubbles. 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."left"
, "right"
, "center"
, "bottom"
, and "top"
. Numeric values of 0 specify left alignment and 1 right alignment.ymod
, it determines position modification of the text labels. In most coordinate systems (projections), the origin is located at the bottom left, so negative xmod
move the text to the left, and negative ymod
values to the bottom.labels
is undefined. Parameters are:
format
of the numbers is "g"
. Otherwise, format="f"
, and text.separator
, text.less.than
, and text.or.more
are used. Also, the numbers are automatically rounded to millions or billions if applicable."f"
, i.e. the standard notation xxx.xxx
, is used. If scientific=TRUE
then "g"
, which means that numbers are formatted scientically, i.e. n.dddE+nn
if needed to save space.format="f"
, and the number of significant digits otherwise.formatC
TRUE
) or landscape (FALSE
)TRUE
) or landscape (FALSE
)legend.size.z
)legend.size.z
)"view"
mode (see tmap_mode
).vignette("tmap-nutshell")
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 * approx_areas(Europe, unit = "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)
Run the code above in your browser using DataLab