Title: | Continuous Cartogram |
---|---|
Description: | Procedures for making continuous cartogram. Procedures available are: flow based cartogram (Gastner & Newman (2004) <doi:10.1073/pnas.0400280101>), fast flow based cartogram (Gastner, Seguy & More (2018) <doi:10.1073/pnas.1712674115>), rubber band based cartogram (Dougenik et al. (1985) <doi:10.1111/j.0033-0124.1985.00075.x>). |
Authors: | Pierre-Andre Cornillon [aut, cre], Florent Demoraes [aut], Flow-Based-Cartograms [cph] (Author of core C code for gsm and gn procedures) |
Maintainer: | Pierre-Andre Cornillon <[email protected]> |
License: | MIT + file LICENSE |
Version: | 1.2-0 |
Built: | 2024-11-03 06:22:53 UTC |
Source: | CRAN |
Coerce an object to a sf object
as.sf(x, ...)
as.sf(x, ...)
x |
object to be coerced |
... |
arguments passed to or from other methods. |
an sf object
Coerce a cartogramR to a sf object returning the sf object used to construct the cartogram with the cartogram as geometry and some more attributes
## S3 method for class 'cartogramR' as.sf(x, ...)
## S3 method for class 'cartogramR' as.sf(x, ...)
x |
a cartogramR object |
... |
arguments passed to or from other methods. |
a sf object including all the data (attributes) contained in the original sf object used to construct the cartogram and
original areas of region (orig_area
)
final/deformed areas of region (final_area
)
target areas of region (target_area
)
original centers (x_orig_centers
and y_orig_centers
)
final centers (x_final_centers
and y_final_centers
)
Coerce an object to a sfc object
as.sfc(x, ...)
as.sfc(x, ...)
x |
object to be coerced |
... |
arguments passed to or from other methods. |
a sfc object
Coerce a cartogramR to a sfc object extracting the component cartogram of the cartogramR object
## S3 method for class 'cartogramR' as.sfc(x, ...)
## S3 method for class 'cartogramR' as.sfc(x, ...)
x |
a cartogramR object |
... |
arguments passed to or from other methods. |
a sfc object
Transform a sf object with several rows (polygons) by region to an sf object with one row by region and thus one multipolygon by region
as.sfmultipolygon(data, idregion, closepolygon = FALSE)
as.sfmultipolygon(data, idregion, closepolygon = FALSE)
data |
a sf object |
idregion |
a character string which indicates the name of the
column (in |
closepolygon |
a boolean (default to |
a sf object with one row by region and one multipolygon by region.
Make a continuous cartogram (density equalizing maps)
cartogramR( data, count, method = c("gsm", "gn", "dcn", "GastnerSeguyMore", "GastnerNewman", "DougenikChrismanNiemeyer"), options = NULL )
cartogramR( data, count, method = c("gsm", "gn", "dcn", "GastnerSeguyMore", "GastnerNewman", "DougenikChrismanNiemeyer"), options = NULL )
data |
a sf object which contains at least two columns:
obviously a geometry column (giving the map) and a column which
contains a count by region (leading to a density by region,
density to be equalized by deformation). Each row of |
count |
a character string which indicates the name of the
column (in |
method |
the method to be used, can be one of the following:
|
options |
a named list given to cartogramR_options function
which process options see cartogramR_options for
details. Default to |
A cartogramR object: a list with the following components:
cartogram: a sf object (in the same order of data
or sorted by idregion
see reordered argument) which contains the initial data
(without the geometry) with three additionnal columns (orig_area: original
areas of regions, final_area: final areas of regions in the cartogram
and target_areas the targeted area) and a geometry part which is
the cartogram (ie the initial polygons after deformation)
orig_centers: the initial centers calculated with sf::st_point_on_surface
final_centers: the centers after deformation
gridx: (for flow-based method) final grid (x-axis) if requested (see cartogramR_options for details).
gridy: (for flow-based method) final grid (y-axis) if requested (see cartogramR_options for details). with additionnal attributes.
Dougenik, J., Chrisman, R. & Niemeyer, D. (1985). An algorithm to construct continuous area cartograms. Professional Geographer 37: 75-81.
Gastner, M. & Newman, M.E.J. (2004). Diffusion-based method for producing density equalizing maps. Proc. Natl. Acad. Sci. USA, 101:7499-7504
Gastner, M., Seguy, V. & More, P. (2018). Fast flow-based algorithm for creating density-equalizing map projections. Proceedings of the National Academy of Sciences USA, 115:E2156-E2164, website: go-cart
data(usa) carto <- cartogramR(usa, "electors64") plot(carto) summary(carto)
data(usa) carto <- cartogramR(usa, "electors64") plot(carto) summary(carto)
Set the options of cartogramR in the correct format
cartogramR_options( options, method = c("gsm", "gn", "dcn", "GastnerSeguyMore", "GastnerNewman", "DougenikChrismanNiemeyer") )
cartogramR_options( options, method = c("gsm", "gn", "dcn", "GastnerSeguyMore", "GastnerNewman", "DougenikChrismanNiemeyer") )
options |
a named list with some (or all) the following components:
|
method |
the method to be used, can be one of the following:
|
a list to be processed by cartogramR
Dougenik, J., Chrisman, R. & Niemeyer, D. (1985). An algorithm to construct continuous area cartograms. Professional Geographer 37: 75-81.
Gastner, M. & Newman, M. E. J. (2004). Diffusion-based method for producing density equalizing maps. Proc. Natl. Acad. Sci. USA, 101:7499-7504
Gastner, M., Seguy, V. & More, P. (2018). Fast flow-based algorithm for creating density-equalizing map projections. Proceedings of the National Academy of Sciences USA, 115:E2156-E2164
data(usa) carto1 <- cartogramR(usa, "electors64", options=list(verbose=1, L=256)) plot(carto1)
data(usa) carto1 <- cartogramR(usa, "electors64", options=list(verbose=1, L=256)) plot(carto1)
Polygon ring are seen from above: exterior ring counter clockwise, holes clockwise
check_ring_dir(polygons, check.only = TRUE)
check_ring_dir(polygons, check.only = TRUE)
polygons |
a sfc object which contains simple feature geometry of
types |
check.only |
a boolean which indicates if the function only
checks the ring direction ( |
Either a logical vector which indicates if line i of polygons
is in the right direction (TRUE
) or not or the corrected sfc object
data(usa) all(check_ring_dir(sf::st_geometry(usa), check.only=TRUE))
data(usa) all(check_ring_dir(sf::st_geometry(usa), check.only=TRUE))
Analyse some of the grid options
dist_between_vertices(data)
dist_between_vertices(data)
data |
a sf object to be used in cartogram. |
a 'dbv.cartogramR' object which is a data-table which contains distance between vertices ('dbv') and polygons names ('L1', 'L2', 'L3') inherited from [sf::st_coordinates]
data(usa) dbv <- dist_between_vertices(data=usa) summary(dbv)
data(usa) dbv <- dist_between_vertices(data=usa) summary(dbv)
This data set is a basemap of mainland France with the population in 2018 (pop2018
), the number of physicians in 2018 (n_physicians
), the number of general practitioner in 2018 (n_gp
) and the number of general practitioner for 100000 inhabitants in 2018 (n_gp_per100000
) in each department (dept_name
or id
).
data(france_dept)
data(france_dept)
A sf object containing 8 columns of data and the geometry Projected CRS: RGF93 / Lambert-93 (EPSG : 2154)
https://www.data.gouv.fr/fr/datasets/admin-express/#_
https://www.insee.fr/fr/statistiques/2012713#tableau-TCRD_004_tab1_departements
https://www.insee.fr/fr/statistiques/2012677#tableau-TCRD_068_tab1_departements
This data set is a basemap of mainland french rivers (name
or id
).
data(france_rivers)
data(france_rivers)
A sf object containing 2 columns of data and the geometry Projected CRS: RGF93 / Lambert-93 (EPSG : 2154)
https://geoservices.ign.fr/telechargement-api
Apply the mapping from the coordinates system used in the polygons (caracterised by the CRS) to the coordinates system used in flow based cartogram
from_coord_polygon(coord, carto)
from_coord_polygon(coord, carto)
coord |
a vector of length 2 or a two columns matrix containing xy coordinates to transform |
carto |
a cartogramR object |
a vector of length 2 or a two columns matrix containing xy coordinates in the coordinate systems of polygons used to build the cartogram
data(usa) carto <- cartogramR(usa, "electors64") from_coord_polygon(c(-0.007, -0.348), carto)
data(usa) carto <- cartogramR(usa, "electors64") from_coord_polygon(c(-0.007, -0.348), carto)
Analyse some of the grid options
grid_analysis(data, gridpower2 = 8:11, pf = 1.5, verbose = FALSE)
grid_analysis(data, gridpower2 = 8:11, pf = 1.5, verbose = FALSE)
data |
a sf object to be used in cartogram. |
gridpower2 |
a vector of exponent (to be raised at the power of 2) that gives the log2(size) of the grid (default to '8:11') |
pf |
Determines space between map and boundary (default to 1.5) |
verbose |
a boolean object to set on verbose mode (default to 'TRUE') |
a 'gridanalysis.cartogramR' object which is a matrix
data(usa) ga <- grid_analysis(data=usa, gridpower2=4:8, verbose=TRUE) summary(ga)
data(usa) ga <- grid_analysis(data=usa, gridpower2=4:8, verbose=TRUE) summary(ga)
Create a sfc object containing final centers, original centers, centers displacement, original graticule or final graticule.
make_layer( x, type = c("final_centers", "original_centers", "centers_translation", "final_graticule", "original_graticule") )
make_layer( x, type = c("final_centers", "original_centers", "centers_translation", "final_graticule", "original_graticule") )
x |
a cartogramR object |
type |
a character string giving the type of layer:
- "final_centers": if |
a sfc object
Plot a cartogram object
## S3 method for class 'cartogramR' plot(x, ...)
## S3 method for class 'cartogramR' plot(x, ...)
x |
a cartogram object |
... |
arguments passed to or from other methods. |
No return value, called for side effects
data(usa) carto <- cartogramR(usa, "electors64") plot(carto)
data(usa) carto <- cartogramR(usa, "electors64") plot(carto)
Plot a dbv.cartogram object
## S3 method for class 'dbv.cartogramR' plot(x, which = 1:2, ask = TRUE, key = TRUE, last = 10, probminx = 0.9, ...)
## S3 method for class 'dbv.cartogramR' plot(x, which = 1:2, ask = TRUE, key = TRUE, last = 10, probminx = 0.9, ...)
x |
a dbv.cartogram object |
which |
if a subset of the plots is required, specify a subset of the
numbers |
ask |
logical; if |
key |
logical; if |
last |
draw the density of distance between vertices for the |
probminx |
the sample quantiles (of distance between vertices)
corresponding to the probability is used as a minimum
of x-axis for the density plot (used only if |
... |
arguments passed to or from other methods. |
The first plot is the density of distance between consecutive vertice by region. Only the upper quantiles are shown. The second plot is a barplot by region of the number of vertice divided by the perimeter of the region
No return value, called for side effects
data(usa) precarto <- precartogramR(usa, method="dcn") plot(precarto)
data(usa) precarto <- precartogramR(usa, method="dcn") plot(precarto)
Plot a gridanalysis.cartogram object
## S3 method for class 'gridanalysis.cartogramR' plot( x, nthsmallest = 5, redrawxaxis = TRUE, type = "b", xlab = NULL, ylab = NULL, ylim = c(0, 20), ... )
## S3 method for class 'gridanalysis.cartogramR' plot( x, nthsmallest = 5, redrawxaxis = TRUE, type = "b", xlab = NULL, ylab = NULL, ylim = c(0, 20), ... )
x |
a gridanalysis.cartogram object |
nthsmallest |
plot only the nthsmallest values among all polygons |
redrawxaxis |
if |
type |
character string (length 1 vector) or vector of 1-character
strings indicating the type of plot for each polygons,
see graphics::matplot for all possible |
xlab |
titles for x axe, as in graphics::matplot. |
ylab |
titles for y axe, as in graphics::matplot. |
ylim |
ranges of y axe, as in graphics::matplot. |
... |
arguments passed to or from other methods. |
No return value, called for side effects
data(usa) precarto <- precartogramR(usa, method="gsm", pf=1.2, verbose=TRUE) plot(precarto)
data(usa) precarto <- precartogramR(usa, method="gsm", pf=1.2, verbose=TRUE) plot(precarto)
Make a pre cartogram analysis
precartogramR( data, method = c("gsm", "gn", "dcn", "GastnerSeguyMore", "GastnerNewman", "DougenikChrismanNiemeyer"), gridpower2 = 8:11, pf = 1.5, verbose = FALSE )
precartogramR( data, method = c("gsm", "gn", "dcn", "GastnerSeguyMore", "GastnerNewman", "DougenikChrismanNiemeyer"), gridpower2 = 8:11, pf = 1.5, verbose = FALSE )
data |
a sf object which contains at least two columns:
obviously a geometry column (giving the map) and a column which
contains a count by region (leading to a density by region,
density to be equalized by deformation). Each row of |
method |
the method to be used, can be one of the following:
|
gridpower2 |
a vector of exponent (to be raised at the power of 2) that
gives the log2(size) of the grid (default to |
pf |
Determines space between map and boundary (default to 1.5);
meaningful for method |
verbose |
a boolean object to set on verbose mode (default to |
either a dbv.cartogramR
object (if method
is dcn
or DougenikChrismanNiemeyer
) see dist_between_vertices
for details or
a gridanalysis.cartogramR
(if method
is gsm
or GastnerSeguyMore
(default), gn
or
GastnerNewman
) see grid_analysis for details
Dougenik, J., Chrisman, R. & Niemeyer, D. (1985). An algorithm to construct continuous area cartograms. Professional Geographer 37: 75-81.
Gastner, M. & Newman, M.E.J. (2004). Diffusion-based method for producing density equalizing maps. Proc. Natl. Acad. Sci. USA, 101:7499-7504
Gastner, M., Seguy, V. & More, P. (2018). Fast flow-based algorithm for creating density-equalizing map projections. Proceedings of the National Academy of Sciences USA, 115:E2156-E2164
data(usa) precarto <- precartogramR(usa) plot(precarto) summary(precarto)
data(usa) precarto <- precartogramR(usa) plot(precarto) summary(precarto)
Print a cartogram object
## S3 method for class 'cartogramR' print(x, ...)
## S3 method for class 'cartogramR' print(x, ...)
x |
a cartogramR object |
... |
arguments passed to or from other methods. |
No return value, called for side effects
Print a summary of a cartogram object
## S3 method for class 'summary.cartogramR' print(x, ...)
## S3 method for class 'summary.cartogramR' print(x, ...)
x |
a summary.cartogramR object |
... |
arguments passed to or from other methods. The following argument is available at this level : digits, the number of significant digits to use when printing. |
x.
data(usa) carto <- cartogramR(usa, "electors64") summary(carto)
data(usa) carto <- cartogramR(usa, "electors64") summary(carto)
Errors of a cartogram object
## S3 method for class 'cartogramR' residuals(object, ...)
## S3 method for class 'cartogramR' residuals(object, ...)
object |
a cartogramR object |
... |
arguments passed to or from other methods. The following arguments are available: - type; a character string giving the type of residuals (see details; can be abbreviated) - "relative error" - "absolute error" - "symmetric difference" - center; a character string giving the type of center (can be abbreviated): - "point_on_surface" (sf::st_point_on_surface applied on original and on deformed/cartogram region). - "deformed_center" (the center function, see cartogramR_options, is applied on region and this center follows the deformation giving the center on the deformed/cartogram region) - "centroid" (centroid of original and deformed/cartogram region). - initial_data; the initial sf object given as input of cartogramR. Only needed for symmetric differences residuals. |
The error vector contains the values of the differences between actual area of regions in the cartogram and theorical area (obtained with conservation of total area and constant density over region in the final cartogram)
Relative error are the error vector divided by the theorical area Symmetric difference are the symmetric difference between actual area of regions in the cartogram and the original area. Each region is scaled to have an area equal to 1 and centered around the chosen center.
A numeric vector which contains for each region observed area minus theorical area
data(usa) carto <- cartogramR(usa, "electors64") residuals(carto)
data(usa) carto <- cartogramR(usa, "electors64") residuals(carto)
Summary of a cartogram object
## S3 method for class 'cartogramR' summary(object, ...)
## S3 method for class 'cartogramR' summary(object, ...)
object |
a cartogramR object |
... |
arguments passed to or from other methods. The following
arguments are available:
- digits integer, used for number formatting with signif if
not specified (i.e., |
A summary.cartogramR object: a list with the following components:
qrr, the summary of absolute relative residuals
qres, the summary of absolute residuals
qsymdiff, the summary of all pairwise symmetric difference beween two
scaled (multi)polygons representative of two regions. These residuals
are calculated only if initial_data
argument is provided.
data(usa) carto <- cartogramR(usa, "electors64") summary(carto)
data(usa) carto <- cartogramR(usa, "electors64") summary(carto)
Summary of a dbv.cartogram object
## S3 method for class 'dbv.cartogramR' summary(object, ...)
## S3 method for class 'dbv.cartogramR' summary(object, ...)
object |
a dbv.cartogramR object |
... |
arguments passed to or from other methods. |
a data-table which contains by region (L3
)
the sample quantiles corresponding to the probability 0.8, 0.85, ...,1
the total number of vertices divided by the
perimeter of the region (the sum of all polygons
perimeter of the region, NbyPerim
)
data(usa) dbv <- dist_between_vertices(data=usa) summary(dbv)
data(usa) dbv <- dist_between_vertices(data=usa) summary(dbv)
Summary of a gridanalysis.cartogram object
## S3 method for class 'gridanalysis.cartogramR' summary(object, ...)
## S3 method for class 'gridanalysis.cartogramR' summary(object, ...)
object |
a gridanalysis.cartogramR object |
... |
arguments passed to or from other methods. |
A vector which indicate the grid size necessary to have more than steps
grid points in each polygon
data(usa) ga <- grid_analysis(data=usa, gridpower2=4:9) summary(ga)
data(usa) ga <- grid_analysis(data=usa, gridpower2=4:9) summary(ga)
Apply the mapping from the coordinates system used in flow based cartogram to the coordinates system used in the polygons (caracterised by the CRS)
to_coord_polygon(coord, carto)
to_coord_polygon(coord, carto)
coord |
a vector of length 2 or a two columns matrix containing xy coordinates to transform |
carto |
a cartogramR object |
a vector of length 2 or a two columns matrix containing xy coordinates in the coordinate systems of polygons used to build the cartogram
data(usa) carto <- cartogramR(usa, "electors64") to_coord_polygon(c(256,256), carto)
data(usa) carto <- cartogramR(usa, "electors64") to_coord_polygon(c(256,256), carto)
This data set is a basemap of the conterminous USA with the the number of electors in the 49 states from 1964 to 2020.
data(usa)
data(usa)
A sf object containing 24 columns of data and the geometry. Projected CRS: US National Atlas Equal Area (EPSG:2163)
Apply the deformation used to build a cartogram to a set of simple geometry coordinates or simple features. The resulting simple geometry object can be used to add geometry features on the cartogram.
warp_features(sfgeom, carto, verbose = FALSE)
warp_features(sfgeom, carto, verbose = FALSE)
sfgeom |
a sf or a sfc object which contains simple feature geometry of
types in the following |
carto |
a cartogramR object |
verbose |
a boolean object to set on verbose mode (default to |
a sf or a sfc object which contains simple feature geometry transformed
data(usa) carto <- cartogramR(usa, "electors64") LA <- sf::st_sfc(sf::st_point(c(-118.243685, 34.052234))) sf::st_crs(LA) <- 4326 moregeom <- warp_features(LA, carto) plot(carto) plot(moregeom, add=TRUE, col=2, pch=15)
data(usa) carto <- cartogramR(usa, "electors64") LA <- sf::st_sfc(sf::st_point(c(-118.243685, 34.052234))) sf::st_crs(LA) <- 4326 moregeom <- warp_features(LA, carto) plot(carto) plot(moregeom, add=TRUE, col=2, pch=15)