Distanamo

This package allows you to create distance cartograms (or distance anamorphoses, hence the name).

Distance cartograms are a type of cartogram that deforms the layers of a map according to the distances between a set of source points and a set of image points.

This is done by extending (by interpolation) to the layer(s) of the study area (territorial divisions, network…) the local displacement between the source coordinates and the image coordinates, derived from the distances between each pair of homologous points (source / image points).

The relation between the source points and the image points, and thus the relative position of the image points compared to the source points, must depend on the studied theme (such as positions in access time for which this package provides some helper functions to generate the image points from the durations between the points).

Installation

You can install distanamo from riatelab’s R-universe with:

install.packages('distanamo', repos = c('https://riatelab.r-universe.dev', 'https://cloud.r-project.org'))

Alternatively, you can install the development version of distanamo from GitHub with:

# install.packages("remotes")
remotes::install_github("riatelab/distanamo")

Note that to install from GitHub, you will need the Rust toolchain to compile the Rust code and that the Minimum Supported Rust Version (MSRV) is 1.82.0.

Usage

Basics

To use this package you need to provide two sets of homologous points : source points and image points. They are used to create an interpolation grid that will be used to deform the layer(s) of interest.

library(sf)
#> Linking to GEOS 3.13.1, GDAL 3.10.3, PROJ 9.6.0; sf_use_s2() is TRUE
library(distanamo)
# Read source points, image points and the background layer to deform
source_pts <- st_read(
  dsn = system.file("gpkg/data-prefecture.gpkg", package = "distanamo"),
  layer = 'prefecture', quiet = TRUE
)
image_pts <- st_read(
  dsn = system.file("gpkg/data-prefecture.gpkg", package = "distanamo"),
  layer = 'image-points', quiet = TRUE
)
background_layer <- st_read(
  dsn = system.file("gpkg/data-prefecture.gpkg", package = "distanamo"),
  layer = 'departement', quiet = TRUE
)

# Create the interpolation grid
igrid <- dc_create(
  source_points = source_pts, 
  image_points = image_pts, 
  precision = 2, 
  bbox = st_bbox(background_layer)
)

# Use it to deform our layer of interest
deformed_background <- dc_interpolate(igrid, background_layer)

# Display the deformed layer
plot(st_geometry(deformed_background))

# Display useful information
summary(igrid)
#> Summary of the interpolation grid:
#> Number of cells: 441 
#> Precision: 50462.76 (α = 2) 
#> Deformation strength: 1.041534 
#> Mean absolute error: 3734.717 
#> RMSE (interp - image): 4989.972 
#> RMSE x (interp - image): 4060.84 
#> RMSE y (interp - image): 2899.896 
#> RMSE (interp - source): 42725.87 
#> RMSE x (interp - source): 32080.25 
#> RMSE y (interp - source): 28219.8 
#> R squared: 0.9997285

# Plot information about the interpolation grid
par(mfrow = c(2, 2))
plot(igrid, ask = FALSE)
par(mfrow = c(1, 1))

Detailed examples and advanced usages

The detailed vignette provided with the package adresses the following features and more advanced usages:

Examples

Example of distance cartogram (Accessibility by bike from the center of Pithiviers)
Example of distance cartogram (Accessibility by car from Caen)

More information about the origin of the method

Related projects

Note that this package is more geared towards the creation of cartograms based on the bidimensional regression technique than specifically towards the study and comparison of two 2D configurations in order to assess their similarity. For this we recommend using the BiDimRegression package which is geared towards applying bidimensional regression in the area of psychological research, face research and comparison of 2D-data patterns in general. Other functionalities close to those proposed in this package (in particular concerning multidimensional scaling and the rotation/scaling/translating/reflection of one set of points to fit another) can also be found in the vegan package for example.

References

About the method

About distance (or time) cartograms in general: their usability, the other methods to create them, etc.

License

GPL-3.0