Description Usage Arguments Value Examples
View source: R/calc_densities.R
Transpose quantitative variables to densitiy variables, which are often needed for choroplets. For example, the colors of a population density map should correspond population density counts rather than absolute population numbers.
1 2 3 4 5 6 7 8 |
shp |
a shape object, i.e., an |
var |
name(s) of a qualtity variable name contained in the |
target |
the target unit, see |
total.area |
total area size of |
suffix |
character that is appended to the variable names. The resulting names are used as column names of the returned data.frame. By default, |
drop |
boolean that determines whether an one-column data-frame should be returned as a vector |
Vector or data.frame (depending on whether length(var)==1
with density values.
1 2 3 4 5 6 7 8 9 10 11 12 13 | if (require(tmap) && packageVersion("tmap") >= "2.0") {
data(NLD_muni)
NLD_muni_pop_per_km2 <- calc_densities(NLD_muni,
target = "km km", var = c("pop_men", "pop_women"))
NLD_muni <- sf::st_sf(data.frame(NLD_muni, NLD_muni_pop_per_km2))
tm_shape(NLD_muni) +
tm_polygons(c("pop_men_km.2", "pop_women_km.2"),
title=expression("Population per " * km^2), style="quantile") +
tm_facets(free.scales = FALSE) +
tm_layout(panel.show = TRUE, panel.labels=c("Men", "Women"))
}
|
Loading required package: tmap
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.