
calc_densities(shp, var, unit = "km", unit.size = 1000, total.area = NA, suffix = "", drop = TRUE)
SpatialPolygons(DataFrame)
shp
datavar/unit^2
.unit="km"
and unit.size=1000
(meaning 1 kilometer equals 1000 coordinate units).shp
in number of squared units (by default kilometers). Useful if the total area of the shp
differs from a reference total area value.length(var)==1
with density values. This can be appended directly to the shape file with append_data
with fixed.order=TRUE
.
data(NLD_muni)
NLD_muni_pop_per_km2 <- calc_densities(NLD_muni,
var = c("pop_men", "pop_women"), suffix = "_km2")
NLD_muni <- append_data(NLD_muni, NLD_muni_pop_per_km2, fixed=TRUE)
tm_shape(NLD_muni) +
tm_polygons(c("pop_men_km2", "pop_women_km2"),
title=expression("Population per " * km^2), style="quantile") +
tm_facets(free.scales = FALSE) +
tm_layout(panel.show = TRUE, panel.labels=c("Men", "Women"))
Run the code above in your browser using DataLab