View source: R/tm_layers_symbols.R
opt_tm_symbols | R Documentation |
Map layer that draws symbols Supported visual variables are:
fill
(the fill color), col
(the border color), size
the symbol size,
shape
the symbol shape, lwd
(line width), lty
(line type), fill_alpha
(fill color alpha transparency) and col_alpha
(border color alpha transparency).
opt_tm_symbols(
points.only = "ifany",
icon.scale = 3,
just = NA,
grob.dim = c(width = 48, height = 48, render.width = 256, render.height = 256)
)
opt_tm_dots(
points.only = "ifany",
icon.scale = 3,
just = NA,
grob.dim = c(width = 48, height = 48, render.width = 256, render.height = 256)
)
opt_tm_bubbles(
points.only = "ifany",
icon.scale = 3,
just = NA,
grob.dim = c(width = 48, height = 48, render.width = 256, render.height = 256)
)
opt_tm_squares(
points.only = "ifany",
icon.scale = 3,
just = NA,
grob.dim = c(width = 48, height = 48, render.width = 256, render.height = 256)
)
tm_symbols(
size = tm_const(),
size.scale = tm_scale(),
size.legend = tm_legend(),
size.chart = tm_chart_none(),
size.free = NA,
fill = tm_const(),
fill.scale = tm_scale(),
fill.legend = tm_legend(),
fill.chart = tm_chart_none(),
fill.free = NA,
col = tm_const(),
col.scale = tm_scale(),
col.legend = tm_legend(),
col.chart = tm_chart_none(),
col.free = NA,
shape = tm_const(),
shape.scale = tm_scale(),
shape.legend = tm_legend(),
shape.chart = tm_chart_none(),
shape.free = NA,
lwd = tm_const(),
lwd.scale = tm_scale(),
lwd.legend = tm_legend(),
lwd.chart = tm_chart_none(),
lwd.free = NA,
lty = tm_const(),
lty.scale = tm_scale(),
lty.legend = tm_legend(),
lty.chart = tm_chart_none(),
lty.free = NA,
fill_alpha = tm_const(),
fill_alpha.scale = tm_scale(),
fill_alpha.legend = tm_legend(),
fill_alpha.chart = tm_chart_none(),
fill_alpha.free = NA,
col_alpha = tm_const(),
col_alpha.scale = tm_scale(),
col_alpha.legend = tm_legend(),
col_alpha.chart = tm_chart_none(),
col_alpha.free = NA,
plot.order = tm_plot_order("size"),
zindex = NA,
group = NA,
group.control = "check",
popup.vars = NA,
popup.format = list(),
hover = "",
id = "",
options = opt_tm_symbols(),
...
)
tm_dots(
fill = tm_const(),
fill.scale = tm_scale(),
fill.legend = tm_legend(),
fill.free = NA,
size = tm_const(),
size.scale = tm_scale(),
size.legend = tm_legend(),
size.free = NA,
lwd = tm_const(),
lwd.scale = tm_scale(),
lwd.legend = tm_legend(),
lwd.free = NA,
lty = tm_const(),
lty.scale = tm_scale(),
lty.legend = tm_legend(),
lty.free = NA,
fill_alpha = tm_const(),
fill_alpha.scale = tm_scale(),
fill_alpha.legend = tm_legend(),
fill_alpha.free = NA,
plot.order = tm_plot_order("size"),
zindex = NA,
group = NA,
group.control = "check",
options = opt_tm_dots(),
...
)
tm_bubbles(
size = tm_const(),
size.scale = tm_scale(),
size.legend = tm_legend(),
size.free = NA,
fill = tm_const(),
fill.scale = tm_scale(),
fill.legend = tm_legend(),
fill.free = NA,
col = tm_const(),
col.scale = tm_scale(),
col.legend = tm_legend(),
col.free = NA,
lwd = tm_const(),
lwd.scale = tm_scale(),
lwd.legend = tm_legend(),
lwd.free = NA,
lty = tm_const(),
lty.scale = tm_scale(),
lty.legend = tm_legend(),
lty.free = NA,
fill_alpha = tm_const(),
fill_alpha.scale = tm_scale(),
fill_alpha.legend = tm_legend(),
fill_alpha.free = NA,
col_alpha = tm_const(),
col_alpha.scale = tm_scale(),
col_alpha.legend = tm_legend(),
col_alpha.free = NA,
plot.order = tm_plot_order("size"),
zindex = NA,
group = NA,
group.control = "check",
options = opt_tm_bubbles(),
...
)
tm_squares(
size = tm_const(),
size.scale = tm_scale(),
size.legend = tm_legend(),
size.free = NA,
fill = tm_const(),
fill.scale = tm_scale(),
fill.legend = tm_legend(),
fill.free = NA,
col = tm_const(),
col.scale = tm_scale(),
col.legend = tm_legend(),
col.free = NA,
lwd = tm_const(),
lwd.scale = tm_scale(),
lwd.legend = tm_legend(),
lwd.free = NA,
lty = tm_const(),
lty.scale = tm_scale(),
lty.legend = tm_legend(),
lty.free = NA,
fill_alpha = tm_const(),
fill_alpha.scale = tm_scale(),
fill_alpha.legend = tm_legend(),
fill_alpha.free = NA,
col_alpha = tm_const(),
col_alpha.scale = tm_scale(),
col_alpha.legend = tm_legend(),
col_alpha.free = NA,
plot.order = tm_plot_order("size"),
zindex = NA,
group = NA,
group.control = "check",
options = opt_tm_squares(),
...
)
points.only |
should only point geometries of the shape object (defined in |
icon.scale |
scaling number that determines how large the icons (or grobs) are in plot mode in comparison to proportional symbols (such as bubbles). For view mode, use the argument |
just |
justification of the text relative to the point coordinates. Either one of the following values: |
grob.dim |
vector of four values that determine how grob objects (see details) are shown in view mode. The first and second value are the width and height of the displayed icon. The third and fourth value are the width and height of the rendered png image that is used for the icon. Generally, the third and fourth value should be large enough to render a ggplot2 graphic successfully. Only needed for the view mode. |
size , size.scale , size.legend , size.chart , size.free |
Visual variable that determines the size. See details. |
fill , fill.scale , fill.legend , fill.chart , fill.free |
Visual variable that determines the fill color. See details. |
col , col.scale , col.legend , col.chart , col.free |
Visual variable that determines the col color. See details. |
shape , shape.scale , shape.legend , shape.chart , shape.free |
Visual variable that determines the shape. See details. |
lwd , lwd.scale , lwd.legend , lwd.chart , lwd.free |
Visual variable that determines the line width. See details. |
lty , lty.scale , lty.legend , lty.chart , lty.free |
Visual variable that determines the line type. See details. |
fill_alpha , fill_alpha.scale , fill_alpha.legend , fill_alpha.chart , fill_alpha.free |
Visual variable that determines the fill color alpha transparency See details. |
col_alpha , col_alpha.scale , col_alpha.legend , col_alpha.chart , col_alpha.free |
Visual variable that determines the border color alpha transparency. See details. |
plot.order |
Specification in which order the spatial features are drawn.
See |
zindex |
Map layers are drawn on top of each other. The |
group |
Name of the group to which this layer belongs.
This is only relevant in view mode, where layer groups can be switched
(see |
group.control |
In view mode, the group control determines how layer
groups can be switched on and off. Options: |
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 |
hover |
name of the data variable that specifies the hover labels |
id |
name of the data variable that specifies the indices of the spatial features.
Only used for |
options |
options passed on to the corresponding |
... |
to catch deprecated arguments from version < 4.0 |
The visual variable arguments (e.g. col
) can be specified with either a data
variable name (e.g., a spatial vector attribute or a raster layer of the object
specified in tm_shape()
), or with a visual value (for col
, a color is expected).
Multiple values can be specified: in that case facets are created.
These facets can be combined with other faceting data variables, specified with tm_facets()
.
The *.scale
arguments determine the used scale to map the data values to
visual variable values. These can be specified with one of the available
tm_scale_*()
functions. The default is specified by the tmap option (tm_options()
) scales.var
.
The *.legend
arguments determine the used legend, specified with tm_legend()
.
The default legend and its settings are determined by the tmap options (tm_options()
) legend.
.
The *.chart
arguments specify additional charts, specified with tm_chart_
, e.g. tm_chart_histogram()
The *.free
arguments determine whether scales are applied freely across facets, or shared.
A logical value is required. They can also be specified with a vector of three
logical values; these determine whether scales are applied freely per facet dimension.
This is only useful when facets are applied (see tm_facets()
).
There are maximally three facet dimensions: rows, columns, and pages. This only
applies for a facet grid (tm_facets_grid()
). For instance, col.free = c(TRUE, FALSE, FALSE)
means that for the visual variable col
, each row of facets will have its own
scale, and therefore its own legend. For facet wraps and stacks
(tm_facets_wrap()
and tm_facets_stack()
) there is only one facet dimension,
so the *.free
argument requires only one logical value.
A symbol shape specification is one of the following three options.
A numeric value that specifies the plotting character of the symbol. See parameter pch
of points
and the last example to create a plot with all options. Note that this is not supported for the "view" mode.
A grob
object, which can be a ggplot2 plot object created with ggplotGrob
. To specify multiple shapes, a list of grob objects is required. See example of a proportional symbol map with ggplot2 plots.
An icon specification, which can be created with tmap_icons
.
To specify multiple shapes (needed for the shapes
argument), a vector or list of these shape specification is required. The shape specification options can also be mixed. For the shapes
argument, it is possible to use a named vector or list, where the names correspond to the value of the variable specified by the shape
argument.
For small multiples, a list of these shape specification(s) should be provided.
metroAfrica = sf::st_intersection(metro, World[World$continent == "Africa", ])
Africa = World[World$continent == "Africa", ]
tm_shape(land) +
tm_raster("cover_cls",
col.scale = tm_scale(
values = cols4all::c4a("brewer.pastel1")[c(3,7,7,2,6,1,2,2)]
),
col.legend = tm_legend_hide()) +
tm_shape(rivers) +
tm_lines(lwd = "strokelwd", lwd.scale = tm_scale_asis(values.scale = .3),
col = cols4all::c4a("brewer.pastel1")[2]) +
tm_shape(Africa, is.main = TRUE) +
tm_borders() +
tm_shape(metroAfrica) +
tm_symbols(fill = "red", shape = "pop2020", size = "pop2020",
size.scale = tm_scale_intervals(
breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6,
values.range = c(0.2,2)
),
size.legend = tm_legend("Population in 2020"),
shape.scale = tm_scale_intervals(
breaks = c(1, 2, 5, 10, 15, 20, 25) * 1e6,
values = c(21, 23, 22, 21, 23, 22)
),
shape.legend = tm_legend_combine("size")) +
tm_labels("name", options = opt_tm_labels(remove.overlap = FALSE))
## to do: replace this example:
## Not run:
if (require(rnaturalearth)) {
airports <- ne_download(scale=10, type="airports", returnclass = "sf")
airplane <- tmap_icons(system.file("img/airplane.png", package = "tmap"))
current.mode <- tmap_mode("view")
tm_shape(NLD_prov, crs = 4326) + tm_polygons() +
tm_shape(airports) +
tm_symbols(shape=airplane, size="natlscale",
legend.size.show = FALSE, scale=1, border.col = NULL, id="name", popup.vars = TRUE)
#tm_view(set.view = c(lon = 15, lat = 48, zoom = 4))
tmap_mode(current.mode)
}
## End(Not run)
########################
## plot symbol shapes
########################
# create grid of 25 points in the Atlantic
library(sf)
atlantic_grid = cbind(expand.grid(x = -51:-47, y = 20:24), id = seq_len(25))
x = st_as_sf(atlantic_grid, coords = c("x", "y"), crs = 4326)
tm_shape(x, bbox = tmaptools::bb(x, ext = 1.2)) +
tm_symbols(shape = "id",
size = 2,
lwd = 2,
fill = "orange",
col = "black",
shape.scale = tm_scale_asis()) +
tm_text("id", ymod = -2)
# also supported in view mode :-)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.