tmap-element that draws bubbles or small dots. Both colors and sizes of the bubbles can be mapped to data variables.
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, ...)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 is used (normally 1).NA (default), no bubble borders are drawn.col is used (normally 1).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 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 shpsizes.legend.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 bubbles. Only when col is set to a variable. The default palette is taken from tm_layout's argument aes.palette.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.jitter times the height of one line of text line.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.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.formatCTRUE) or landscape (FALSE)TRUE) or landscape (FALSE)legend.size.z)legend.size.z)"view" mode (see tmap_mode).title.col for tm_dotslegend.col.show for tm_dotslegend.col.is.portrait for tm_dotslegend.col.z shortcut for tm_dotstm_bubblesby 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.
vignette("tmap-nutshell")
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