
tmap-element
that draws a raster. Either a fixed color is used, or a color palette is mapped to a data variable. By default, a divering color palette is used for numeric variables and a qualitative palette for categorical variables.tm_raster(col = "grey70", alpha = NA, palette = NULL, n = 5,
style = "pretty", breaks = NULL, labels = NULL,
auto.palette.mapping = TRUE, contrast = 1, max.categories = 12,
colorNA = NA, textNA = "Missing", text_separator = "to",
text_less_than = "Less than", text_or_more = "or more", title = NA,
legend.is.portrait = TRUE, legend.hist = FALSE, legend.hist.title = NA,
legend.z = NA, legend.hist.z = NA)
shp
. In the latter case, either the data variable contains color values, or values (numeric or categorical) that will be depicted by a color palette (see pa
col
is used (normally 1).RColorBrewer::display.brewer.all()
for options. Use a "-"
as prefix to reverse the palette. By default, "RdYlGn"
is taken for numeric variables and "Dark2"
for categorical variables.col
is a numeric variable)col
is a numeric variable): e.g. "fixed", "equal", "pretty", "quantile", or "kmeans". See the details in classIntervals
.style=="fixed"
, breaks should be specifiedauto.palette.mapping=TRUE
). Both numbers should be between 0 and 1. The first number determines where the palette begins, and tcol
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
, then levels are combined.NA
to omit text for missing values in the legendTRUE
) or landscape (FALSE
)vignette("tmap-nutshell")
}data(land)
data(World)
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", max.categories = 20, palette=pal20, title="Global Land Cover") +
tm_layout_World(inner.margins=0, legend.position = c("left","bottom"))
pal8 <- c("#33A02C", "#B2DF8A", "#FDBF6F", "#1F78B4", "#999999", "#E31A1C", "#E6E6E6", "#A6CEE3")
tm_shape(land, ylim = c(-88,88), relative=FALSE) +
tm_raster("cover_cls", palette = pal8, title="Global Land Cover") +
tm_shape(World) +
tm_borders() +
tm_layout_World(inner.margins=0,
legend.position = c("left","bottom"),
legend.bg.color = "white", legend.bg.alpha=.2,
legend.frame="gray50", legend.width=.2)
tm_shape(land, ylim = c(-88,88), relative=FALSE) +
tm_raster("trees", palette = "Greens", title="Percent Tree Cover") +
tm_shape(World) +
tm_borders() +
tm_layout(inner.margins=0,
legend.position = c("left","bottom"), bg.color="lightblue")
tm_shape(land) +
tm_raster("black") +
tm_facets(by="cover_cls") +
tm_layout(inner.margins=0,
title.position = c("left", "bottom"), title.bg.color="gray80")
Run the code above in your browser using DataLab