tm_fill | R Documentation |
Creates a tmap-element
that draws the polygons. tm_fill
fills the polygons. Either a fixed color is used, or a color palette is mapped to a data variable. tm_borders
draws the borders of the polygons. tm_polygons
fills the polygons and draws the polygon borders.
tm_fill(
col = NA,
alpha = NA,
palette = NULL,
convert2density = FALSE,
area = NULL,
n = 5,
style = ifelse(is.null(breaks), "pretty", "fixed"),
style.args = list(),
as.count = NA,
breaks = NULL,
interval.closure = "left",
labels = NULL,
drop.levels = FALSE,
midpoint = NULL,
stretch.palette = TRUE,
contrast = NA,
colorNA = NA,
textNA = "Missing",
showNA = NA,
colorNULL = NA,
thres.poly = 0,
title = NA,
legend.show = TRUE,
legend.format = list(),
legend.is.portrait = TRUE,
legend.reverse = FALSE,
legend.hist = FALSE,
legend.hist.title = NA,
legend.z = NA,
legend.hist.z = NA,
id = NA,
interactive = TRUE,
popup.vars = NA,
popup.format = list(),
zindex = NA,
group = NA,
auto.palette.mapping = NULL,
max.categories = NULL,
...
)
tm_borders(
col = NA,
lwd = 1,
lty = "solid",
alpha = NA,
zindex = NA,
group = NA
)
tm_polygons(
col = NA,
alpha = NA,
border.col = NA,
border.alpha = NA,
zindex = NA,
group = NA,
...
)
col |
For
For |
alpha |
transparency number between 0 (totally transparent) and 1 (not transparent). By default, the alpha value of the |
palette |
a palette name or a vector of colors. See |
convert2density |
boolean that determines whether |
area |
Name of the data variable that contains the area sizes in squared kilometer. |
n |
preferred number of classes (in case |
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: |
labels |
labels of the classes. |
drop.levels |
should unused classes be omitted? |
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 |
color used 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 |
thres.poly |
number that specifies the threshold at which polygons are taken into account. The number itself corresponds to the proportion of the area sizes of the polygons to the total polygon size. By default, all polygons are drawn. To ignore polygons that are not visible in a normal plot, a value like |
title |
title of the legend element |
legend.show |
logical that determines whether the legend is shown |
legend.format |
list of formatting options for the legend numbers. Only applicable if
|
legend.is.portrait |
logical that determines whether the legend is in portrait mode ( |
legend.reverse |
logical that determines whether the items are shown in reverse order, i.e. from bottom to top when |
legend.hist |
logical that determines whether a histogram is shown |
legend.hist.title |
title for the histogram. By default, one title is used for both the histogram and the normal legend. |
legend.z |
index value that determines the position of the legend element 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.hist.z |
index value that determines the position of the histogram legend element |
id |
name of the data variable that specifies the indices of the polygons. Only used for |
interactive |
logical that determines whether this layer is interactive in view mode (e.g. hover text, popup, and click event in shiny apps) |
popup.vars |
names of data variables that are shown in the popups in |
popup.format |
list of formatting options for the popup values. See the argument |
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 |
... |
for |
lwd |
border line width (see |
lty |
border line type (see |
border.col |
border line color |
border.alpha |
transparency number between 0 (totally transparent) and 1 (not transparent). By default, the alpha value of the |
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 argument of tm_fill
(and tm_polygons
) is col
. In the latter case, the arguments, except for thres.poly
, and 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.
tmap-element
Tennekes, M., 2018, tmap: Thematic Maps in R, Journal of Statistical Software, 84(6), 1-39, \Sexpr[results=rd]{tools:::Rd_expr_doi("10.18637/jss.v084.i06")}
data(World)
# Constant fill
tm_shape(World) + tm_fill("darkolivegreen3") + tm_format("World", title="A green World")
# Borders only
tm_shape(World) + tm_borders()
# Data variable containing colours values
World$isNLD <- ifelse(World$name=="Netherlands", "darkorange", "darkolivegreen3")
tm_shape(World) +
tm_fill("isNLD") +
tm_layout("Find the Netherlands!")
tm_shape(World, projection = "+proj=eck4") +
tm_polygons("economy", title="Economy", id="name") +
tm_text("iso_a3", size="AREA", scale=1.5) +
tm_format("World")
# Numeric data variable
tm_shape(World, projection = "+proj=eck4") +
tm_polygons("HPI", palette="RdYlGn", style="cont", n=8,
title="Happy Planet Index", id="name") +
tm_text("iso_a3", size="AREA", scale=1.5) +
tm_style("grey") +
tm_format("World")
## Not run:
data(NLD_prov, NLD_muni)
# Map coloring algorithm
tm_shape(NLD_prov) +
tm_fill("name", legend.show = FALSE) +
tm_shape(NLD_muni) +
tm_polygons("MAP_COLORS", palette="Greys", alpha = .25) +
tm_shape(NLD_prov) +
tm_borders(lwd=2) +
tm_text("name", shadow=TRUE) +
tm_format("NLD", title="Dutch provinces and\nmunicipalities", bg.color="white")
# Cartogram
if (require(cartogram)) {
NLD_prov_pop <- cartogram(NLD_prov, "population")
tm_shape(NLD_prov_pop) +
tm_polygons("origin_non_west", title = "Non-western origin (%)")
}
## End(Not run)
# TIP: check out these examples in view mode, enabled with tmap_mode("view")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.