Construct a continuous area cartogram by a rubber sheet distortion algorithm (Dougenik et al. 1985), non-contiguous Area Cartograms (Olson 1976), and non-overlapping Circles Cartogram (Dorling el al. 1996) in R.
You can install the cartogram package from CRAN as follows:
install.packages("cartogram")
To upgrade to the latest development version of
cartogram
, install the package devtools
and
run the following command:
::install_github("sjewo/cartogram") devtools
sp
, rgdal
and
maptools
from examples and suggestions.
cartogram_cont
has a new parameter
verbose = FALSE
to hide print of size error on each
iteration.library(cartogram)
library(sf)
#> Linking to GEOS 3.11.0, GDAL 3.5.3, PROJ 9.1.0; sf_use_s2() is TRUE
library(tmap)
data("World")
# keep only the african continent
<- World[World$continent == "Africa", ]
afr
# project the map
<- st_transform(afr, 3395)
afr
# construct cartogram
<- cartogram_cont(afr, "pop_est", itermax = 5)
afr_cont
# plot it
tm_shape(afr_cont) + tm_polygons("pop_est", style = "jenks") +
tm_layout(frame = FALSE, legend.position = c("left", "bottom"))
Many thanks to @rCarto and @neocarto for contributing the code!
# construct cartogram
<- cartogram_ncont(afr, "pop_est")
afr_ncont
# plot it
tm_shape(afr) + tm_borders() +
tm_shape(afr_ncont) + tm_polygons("pop_est", style = "jenks") +
tm_layout(frame = FALSE, legend.position = c("left", "bottom"))
Many thanks to @rCarto for contributing the code!
# construct cartogram
<- cartogram_dorling(afr, "pop_est")
afr_dorling
# plot it
tm_shape(afr) + tm_borders() +
tm_shape(afr_dorling) + tm_polygons("pop_est", style = "jenks") +
tm_layout(frame = FALSE, legend.position = c("left", "bottom"))