tm_text {tmap} | R Documentation |
Add text labels
Description
Creates a tmap-element
that adds text labels.
Usage
tm_text(
text,
size = 1,
col = NA,
root = 3,
clustering = FALSE,
size.lim = NA,
sizes.legend = NULL,
sizes.legend.labels = NULL,
sizes.legend.text = "Abc",
n = 5,
style = ifelse(is.null(breaks), "pretty", "fixed"),
style.args = list(),
as.count = NA,
breaks = NULL,
interval.closure = "left",
palette = NULL,
labels = NULL,
drop.levels = FALSE,
labels.text = NA,
midpoint = NULL,
stretch.palette = TRUE,
contrast = NA,
colorNA = NA,
textNA = "Missing",
showNA = NA,
colorNULL = 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 = "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.size.reverse = FALSE,
legend.col.reverse = FALSE,
legend.hist = FALSE,
legend.hist.title = NA,
legend.size.z = NA,
legend.col.z = NA,
legend.hist.z = NA,
id = NA,
zindex = NA,
group = NA,
auto.palette.mapping = NULL,
max.categories = NULL
)
Arguments
text |
name of the variable in the shape object that contains the text labels |
size |
relative size of the text labels (see note). Either one number, a name of a numeric variable in the shape data that is used to scale the sizes proportionally, or the value |
col |
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 |
root number to which the font sizes are scaled. Only applicable if |
clustering |
value that determines whether the text labels are clustered in |
size.lim |
vector of two limit values of the |
sizes.legend |
vector of text sizes that are shown in the legend. By default, this is determined automatically. |
sizes.legend.labels |
vector of labels for that correspond to |
sizes.legend.text |
vector of example text to show in the legend next to sizes.legend.labels. By default "Abc". When |
n |
preferred number of color scale classes. Only applicable when |
style |
method to process the color scale when |
style.args |
arguments passed on to |
as.count |
when |
breaks |
in case |
interval.closure |
value that determines whether where the intervals are closed: |
palette |
a palette name or a vector of colors. See |
labels |
labels of the color classes, applicable if |
drop.levels |
should unused color classes be omitted? |
labels.text |
Example text to show in the legend next to the |
midpoint |
The value mapped to the middle color of a diverging palette. By default it is set to 0 if negative and positive values are present. In that case, the two sides of the color palette are assigned to negative respectively positive values. If all values are positive or all values are negative, then the midpoint is set to |
stretch.palette |
Logical that determines whether the categorical color palette should be stretched if there are more categories than colors. If |
contrast |
vector of two numbers that determine the range that is used for sequential and diverging palettes (applicable when |
colorNA |
colour for missing values. Use |
textNA |
text used for missing values. |
showNA |
logical that determines whether missing values are named in the legend. By default ( |
colorNULL |
colour for polygons that are shown on the map that are out of scope |
fontface |
font face of the text labels. By default, determined by the fontface argument of |
fontfamily |
font family of the text labels. By default, determined by the fontfamily argument of |
alpha |
transparency number between 0 (totally transparent) and 1 (not transparent). By default, the alpha value of the |
case |
case of the font. Use "upper" to generate upper-case text, "lower" to generate lower-case text, and |
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 |
bg.color |
background color of the text labels. By default, |
bg.alpha |
number between 0 and 1 that specifies the transparency of the text background (0 is totally transparent, 1 is solid background). |
size.lowerbound |
lowerbound for |
print.tiny |
boolean, see |
scale |
text size multiplier, useful in case |
auto.placement |
logical (or numeric) that determines whether the labels are placed automatically. If |
remove.overlap |
logical that determines whether the overlapping labels are removed |
along.lines |
logical that determines whether labels are rotated along the spatial lines. Only applicable if a spatial lines shape is used. |
overwrite.lines |
logical that determines whether the part of the lines below the text labels is removed. Only applicable if a spatial lines shape is used. |
just |
justification of the text relative to the point coordinates. Either one of the following values: |
xmod |
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 |
vertical position modification. See xmod. |
title.size |
title of the legend element regarding the text sizes |
title.col |
title of the legend element regarding the text colors |
legend.size.show |
logical that determines whether the legend for the text sizes is shown |
legend.col.show |
logical that determines whether the legend for the text colors is shown |
legend.format |
list of formatting options for the legend numbers. Only applicable if
|
legend.size.is.portrait |
logical that determines whether the legend element regarding the text sizes is in portrait mode ( |
legend.col.is.portrait |
logical that determines whether the legend element regarding the text colors is in portrait mode ( |
legend.size.reverse |
logical that determines whether the items of the legend regarding the text sizes are shown in reverse order, i.e. from bottom to top when |
legend.col.reverse |
logical that determines whether the items of the legend regarding the text colors are shown in reverse order, i.e. from bottom to top when |
legend.hist |
logical that determines whether a histogram is shown regarding the text colors |
legend.hist.title |
title for the histogram. By default, one title is used for both the histogram and the normal legend for text colors. |
legend.size.z |
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. |
legend.col.z |
index value that determines the position of the legend element regarding the text colors. (See |
legend.hist.z |
index value that determines the position of the histogram legend element. (See |
id |
name of the data variable that specifies the indices of the text labels. Only used for |
zindex |
zindex of the pane in view mode. By default, it is set to the layer number plus 400. By default, the tmap layers will therefore be placed in the custom panes |
group |
name of the group to which this layer belongs in view mode. Each group can be selected or deselected in the layer control item. Set |
auto.palette.mapping |
deprecated. It has been replaced by |
max.categories |
deprecated. It has moved to |
Value
Note
The absolute fontsize (in points) is determined by the (ROOT) viewport, which may depend on the graphics device.
References
Tennekes, M., 2018, tmap: Thematic Maps in R, Journal of Statistical Software, 84(6), 1-39, doi:10.18637/jss.v084.i06
See Also
Examples
current.mode <- tmap_mode("plot")
data(World, metro)
tm_shape(World) +
tm_text("name", size="AREA")
tm_shape(World) +
tm_text("name", size="pop_est", col="continent", palette="Dark2",
title.size = "Population", title.col="Continent") +
tm_legend(outside = TRUE)
tmap_mode("view")
## Not run:
require(tmaptools)
metro_aus <- crop_shape(metro, bb("Australia"))
tm_shape(metro_aus) +
tm_dots() +
tm_text("name", just = "top")
# alternative
tm_shape(metro_aus) +
tm_markers(text = "name")
## End(Not run)
# restore current mode
tmap_mode(current.mode)