tm_raster | R Documentation |
Creates a tmap-element
that draws a raster. For coloring, there are three options: 1) a fixed color is used, 2) a color palette is mapped to a data variable, 3) RGB values are used. The function tm_raster
is designed for options 1 and 2, while tm_rgb
is used for option 3.
tm_raster(
col = NA,
alpha = NA,
palette = 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,
saturation = 1,
interpolate = NA,
colorNA = NULL,
textNA = "Missing",
showNA = NA,
colorNULL = NULL,
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,
zindex = NA,
group = NA,
auto.palette.mapping = NULL,
max.categories = NULL,
max.value = 255
)
tm_rgb(
r = 1,
g = 2,
b = 3,
alpha = NA,
saturation = 1,
interpolate = TRUE,
max.value = 255,
...
)
tm_rgba(
r = 1,
g = 2,
b = 3,
a = 4,
alpha = NA,
saturation = 1,
interpolate = TRUE,
max.value = 255,
...
)
col |
three options: the name of a data variable that is contained in |
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 |
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 |
saturation |
Number that determines how much saturation (also known as chroma) is used: |
interpolate |
Should the raster image be interpolated? By default |
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 |
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 of the legend regarding the text sizes 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 |
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 |
max.value |
for |
r |
raster band for the red channel. It should be an integer between 1 and the number of raster layers. |
g |
raster band for the green channel. It should be an integer between 1 and the number of raster layers. |
b |
raster band for the blue channel. It should be an integer between 1 and the number of raster layers. |
... |
arguments passed on from |
a |
raster band for the alpha channel. It should be an integer between 1 and the number of raster layers. |
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_raster
is 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.
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, land, metro)
pal8 <- c("#33A02C", "#B2DF8A", "#FDBF6F", "#1F78B4", "#999999", "#E31A1C", "#E6E6E6", "#A6CEE3")
tm_shape(land, ylim = c(-88,88)) +
tm_raster("cover_cls", palette = pal8, title = "Global Land Cover") +
tm_shape(metro) + tm_dots(col = "#E31A1C") +
tm_shape(World) +
tm_borders(col = "black") +
tm_layout(scale = .8,
legend.position = c("left","bottom"),
legend.bg.color = "white", legend.bg.alpha = .2,
legend.frame = "gray50")
## Not run:
pal20 <- c("#003200", "#3C9600", "#006E00", "#556E19", "#00C800", "#8CBE8C",
"#467864", "#B4E664", "#9BC832", "#EBFF64", "#F06432", "#9132E6",
"#E664E6", "#9B82E6", "#B4FEF0", "#646464", "#C8C8C8", "#FF0000",
"#FFFFFF", "#5ADCDC")
tm_shape(land) +
tm_raster("cover", palette = pal20, title = "Global Land Cover") +
tm_layout(scale=.8, legend.position = c("left","bottom"))
## End(Not run)
tm_shape(land, ylim = c(-88,88)) +
tm_raster("trees", palette = "Greens", title = "Percent Tree Cover") +
tm_shape(World) +
tm_borders() +
tm_layout(legend.position = c("left", "bottom"), bg.color = "lightblue")
## Not run:
tm_shape(land) +
tm_raster("black") +
tm_facets(by="cover_cls")
## 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.