Learn R Programming

tmap (version 0.7)

calc_densities: Calculate densities

Description

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.

Usage

calc_densities(shp, var, total.area.km2 = NA, units = "km2", suffix = "",
  drop = TRUE)

Arguments

shp
a shape object, i.e. a SpatialPolygons(DataFrame)
var
name(s) of a qualtity variable name contained in the map data
total.area.km2
total area size of shp in number of squared kilometers. If NA, and unit="km2", then the polygon coordinates are assumed to be in meters.
units
the units of the area sizes, either "m2" or "km2". In other words, either var/m2 or var/km2 density values are calculated.
suffix
character that is appended to the variable names. The resulting names are used as column names of the returned data.frame.
drop
boolean that determines whether an one-column data-frame should be returned as a vector

Value

  • Vector or data.frame (depending on whether length(var)==1 with density values. This can be appended directly to the shape file with append_data with fixed.order=TRUE.

Examples

Run this code
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)

qtm(NLD_muni, fill=c("pop_men_km2", "pop_women_km2"), nrow=1)

Run the code above in your browser using DataLab