Learn R Programming

tmap (version 1.4-1)

tm_bubbles: Draw bubbles or dots

Description

Creates a tmap-element that draws bubbles or small dots. Both colors and sizes of the bubbles can be mapped to data variables.

Usage

tm_bubbles(size = 0.2, col = NA, alpha = NA, border.col = NA, border.lwd = 1, border.alpha = NA, scale = 1, perceptual = FALSE, size.lim = NA, sizes.legend = NULL, sizes.legend.labels = NULL, n = 5, style = ifelse(is.null(breaks), "pretty", "fixed"), breaks = NULL, palette = NULL, labels = NULL, auto.palette.mapping = TRUE, contrast = NA, max.categories = 12, colorNA = NA, textNA = "Missing", showNA = NA, jitter = 0, 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)
tm_dots(col = NA, size = 0.02, title = NA, legend.show = TRUE, legend.is.portrait = TRUE, legend.z = NA, ...)

Arguments

size
a single value or a shp data variable that determines the bubble sizes. The reference value size=1 corresponds to the area of bubbles that have the same height as one line of text. If a data variable is provided, the bubble sizes are scaled proportionally (or perceptually, see perceptual) where the largest bubble will get size=1. If multiple values are specified, small multiples are drawn (see details).
col
color(s) of the bubble. Either a color (vector), or categorical variable name(s). If multiple values are specified, small multiples are drawn (see details).
alpha
transparency number between 0 (totally transparent) and 1 (not transparent). By default, the alpha value of the col is used (normally 1).
border.col
color of the bubble borders.
border.lwd
line width of the bubble borders. If NA (default), no bubble borders are drawn.
border.alpha
transparency number, regarding the bubble borders, between 0 (totally transparent) and 1 (not transparent). By default, the alpha value of the col is used (normally 1).
scale
bubble size multiplier number.
perceptual
logical that determines whether bubbles are scales with a perceptually (TRUE) or mathematically (FALSE, default value). The perceived area of larger bubbles is often underestimated. Flannery (1971) experimentally derived a method to compensate this, which is enabled by this argument.
size.lim
vector of two limit values of the size variable. Only bubbles are drawn whose value is greater than or equal to the first value. Bubbles 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
sizes.legend
vector of bubble 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.
n
preferred number of color scale classes. Only applicable when col is a numeric variable name.
style
method to process the color scale when 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".
breaks
in case style=="fixed", breaks should be specified
palette
color palette (see RColorBrewer::display.brewer.all) for the bubbles. Only when col is set to a variable. The default palette is taken from tm_layout's argument aes.palette.
labels
labels of the classes
auto.palette.mapping
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 is there are more levels than colors.
contrast
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).
max.categories
in case 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.
colorNA
colour for missing values. Use NULL for transparency.
textNA
text used for missing values.
showNA
logical that determines whether missing values are named in the legend. By default (NA), this depends on the presence of missing values.
jitter
number that determines the amount of jittering, i.e. the random noise added to the position of the bubbles. 0 means no jittering is applied, any positive number means that the random noise has a standard deviation of jitter times the height of one line of text line.
xmod
horizontal position modification of the bubbles, in terms of 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 bubbles. See also jitter for random position modifications. In most coordinate systems (projections), the origin is located at the bottom left, so negative xmod move the bubbles to the left, and negative ymod values to the bottom.
ymod
vertical position modification. See xmod.
title.size
title of the legend element regarding the bubble sizes
title.col
title of the legend element regarding the bubble colors
legend.size.show
logical that determines whether the legend for the bubble sizes is shown
legend.col.show
logical that determines whether the legend for the bubble colors is shown
legend.format
list of formatting options for the legend numbers. Only applicable if labels is undefined. Parameters are:
scientific
Should the labels be formatted scientically? If so, square brackets are used, and the 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.

format
By default, "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.

digits
Number of digits after the decimal point if format="f", and the number of significant digits otherwise.

text.separator
Character string to use to separate numbers in the legend (default: "to").

text.less.than
Character string to use to translate "Less than" (which is the default).

text.or.more
Character string to use to translate "or more" (which is the default).

...
Other arguments passed on to formatC

legend.size.is.portrait
logical that determines whether the legend element regarding the bubble sizes is in portrait mode (TRUE) or landscape (FALSE)
legend.col.is.portrait
logical that determines whether the legend element regarding the bubble colors is in portrait mode (TRUE) or landscape (FALSE)
legend.hist
logical that determines whether a histogram is shown regarding the bubble colors
legend.hist.title
title for the histogram. By default, one title is used for both the histogram and the normal legend for bubble colors.
legend.size.z
index value that determines the position of the legend element regarding the bubble 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 bubble colors. (See legend.size.z)
legend.hist.z
index value that determines the position of the histogram legend element. (See legend.size.z)
id
name of the data variable that specifies the indices of the bubbles. Only used for "view" mode (see tmap_mode).
title
shortcut for title.col for tm_dots
legend.show
shortcut for legend.col.show for tm_dots
legend.is.portrait
shortcut for legend.col.is.portrait for tm_dots
legend.z
shortcut for legend.col.z shortcut for tm_dots
...
arguments passed on to tm_bubbles

Value

tmap-element

Details

Small multiples can be drawn in two ways: either by specifying the by argument in tm_facets, or by defining multiple variables in the aesthetic arguments. The aesthetic arguments of tm_bubbles are size and col. In the latter case, the arguments, except for the ones starting with legend., can be specified for small multiples as follows. If the argument normally only takes a single value, such as n, then a vector of those values can be specified, one for each small multiple. If the argument normally can take a vector, such as palette, then a list of those vectors (or values) can be specified, one for each small multiple.

References

Flannery J (1971). The Relative Effectiveness of Some Common Graduated Point Symbols in the Presentation of Quantitative Data. Canadian Cartographer, 8 (2), 96-109.

See Also

vignette("tmap-nutshell")

Examples

Run this code
data(World, metro)
metro$growth <- (metro$pop2020 - metro$pop2010) / (metro$pop2010 * 10) * 100

tm_shape(World) +
    tm_fill("grey70") +
tm_shape(metro) +
    tm_bubbles("pop2010", col = "growth", 
        border.col = "black", border.alpha = .5, 
        style="fixed", breaks=c(-Inf, seq(0, 6, by=2), Inf),
        palette="-RdYlBu", contrast=1, 
        title.size="Metro population", 
        title.col="Growth rate (%)") + 
tm_format_World()

## Not run: 
# x <- sample_dots(World, vars="gdp_md_est", convert2density = TRUE, w = 100000)
# tm_shape(x) + 
# 	tm_dots() + 
# tm_layout("World GDP (one dot is 100 billon dollars)", title.position = c("right", "bottom"))
# ## End(Not run)
# TIP: check out these examples in view mode, enabled with tmap_mode("view")

Run the code above in your browser using DataLab