cartogram (version 0.2.0)

cartogram_cont: Calculate Contiguous Cartogram Boundaries

Description

Construct a continuous area cartogram by a rubber sheet distortion algorithm (Dougenik et al. 1985)

Usage

cartogram_cont(
  x,
  weight,
  itermax = 15,
  maxSizeError = 1.0001,
  prepare = "adjust",
  threshold = 0.05
)

# S3 method for SpatialPolygonsDataFrame cartogram_cont( x, weight, itermax = 15, maxSizeError = 1.0001, prepare = "adjust", threshold = 0.05 )

# S3 method for sf cartogram_cont( x, weight, itermax = 15, maxSizeError = 1.0001, prepare = "adjust", threshold = 0.05 )

Arguments

x

SpatialPolygonDataFrame or an sf object

weight

Name of the weighting variable in x

itermax

Maximum iterations for the cartogram transformation, if maxSizeError ist not reached

maxSizeError

Stop if meanSizeError is smaller than maxSizeError

prepare

Weighting values are adjusted to reach convergence much earlier. Possible methods are "adjust", adjust values to restrict the mass vector to the quantiles defined by threshold and 1-threshold (default), "remove", remove features with values lower than quantile at threshold, "none", don't adjust weighting values

threshold

Define threshold for data preparation

Value

An object of the same class as x

References

Dougenik, J. A., Chrisman, N. R., & Niemeyer, D. R. (1985). An Algorithm To Construct Continuous Area Cartograms. In The Professional Geographer, 37(1), 75-81.

Examples

Run this code
# NOT RUN {
library(maptools)
library(cartogram)
library(rgdal)
data(wrld_simpl)

# Remove uninhabited regions
afr <- spTransform(wrld_simpl[wrld_simpl$REGION==2 & wrld_simpl$POP2005 > 0,], 
                    CRS("+init=epsg:3395"))

# Create cartogram
afr_carto <- cartogram_cont(afr, "POP2005", 3)

# Plot 
par(mfcol=c(1,2))
plot(afr, main="original")
plot(afr_carto, main="distorted (sp)")

# Same with sf objects
library(sf)

afr_sf = st_as_sf(afr)

afr_sf_carto <- cartogram_cont(afr_sf, "POP2005", 3)

# Plot 
par(mfcol=c(1,3))
plot(afr, main="original")
plot(afr_carto, main="distorted (sp)")
plot(st_geometry(afr_sf_carto), main="distorted (sf)")

# }

Run the code above in your browser using DataLab