terra icon indicating copy to clipboard operation
terra copied to clipboard

cartogram un-centered polygons

Open AMBarbosa opened this issue 1 month ago • 0 comments

Hi, I'm getting visibly different outputs with the terra and cartogram packages, though I don't know which (if) one is supposed to be more correct. The polygon in the middle (with value 12) looks the same in both non-contiguous cartograms, but other polygons are quite different. More importantly, terra::cartogram polygons have different centroids from the input polygons. Is this expected / desired? (Note: the map is projected because cartogram requires that)

require(terra)
require(cartogram)
require(raster)

v <- vect(system.file("ex/lux.shp", package="terra"))
v <- project(v, "+proj=moll")
v$value <- 1:12


# with terra pkg:

pnc <- terra::cartogram(v, "value", "nc")
pcirc <- terra::cartogram(v, "value", "circles")

plot(v, col="light gray", border="gray", main = "terra pkg")
lines(pnc, col="red", lwd=2)
lines(pcirc, col="blue", lwd=2)
text(v, "value", halo=TRUE)


# with cartogram pkg:

pnc2 <- cartogram::cartogram_ncont(as(v, "Spatial"), "value")
pcirc2 <- cartogram::cartogram_dorling(as(v, "Spatial"), "value")

plot(v, col="light gray", border="gray", main = "cartogram pkg")
lines(pnc2, col="red", lwd=2)
lines(pcirc2, col="blue", lwd=2)
text(v, "value", halo=TRUE)
Image

AMBarbosa avatar Dec 09 '25 17:12 AMBarbosa