library(sf)
library(cartogram)
nc = st_read(system.file("shape/nc.shp", package="sf"), quiet = TRUE)
# transform to NAD83 / UTM zone 16N
nc_utm <- st_transform(nc, 26916)
# Create cartogram
nc_utm_carto <- cartogram_cont(nc_utm, weight = "BIR74", itermax = 5)
# Plot
par(mfrow=c(2,1))
plot(nc[,"BIR74"], main="original", key.pos = NULL, reset = FALSE)
plot(nc_utm_carto[,"BIR74"], main="distorted", key.pos = NULL, reset = FALSE)
Run the code above in your browser using DataLab