Skip to content

stephaneghozzi/GridCartogramGermany

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Grid Cartograms for Germany

Reads state and county shape files and produces hexagonal grid cartograms as GeoJSONs. The idea is to display each region (state or county) with equal importance. This provides an alternative to using symbols such as bubbles.

This project applies the library geogrid, repairs the grids and tries (manually) to find a good arrangement, inspired by the New York Times' visualization of the 2018 House election results.

Two illustrations:

Grid cartogram for German counties and Berlin districts

Grid cartogram for German states

Germany poses some challenges for chloropleth maps, maps with symbols as well as classical cartograms: states and counties have very different sizes, typically in inverse proportion of their population. Moreover, it is common to have nested states and counties, e.g. Berlin in Brandburg and many counties in Bavaria (Bayern).

Grid cartograms offer an alternative, where the value to be displayed for each region is equally readable (no overlapping, none so small that one cannot see them). This comes at the cost of only approximative spatial locations and neighbourhoods.

Shapes

The grid cartograms retained are saved in out/chosen_grids/. The results for all of Germany used for the illustrations above are out/chosen_grids/germany_states_grid_09.geojson and out/chosen_grids/germany_counties_grid.geojson.

The original shape files were provided by the Federal Agency for Cartography and Geodesy (BKG). The county-level incorporates the Kreise (counties) as well as the 12 Bezirke (districts) of Berlin, as is usually done at the Robert Koch Institute (RKI), which supported this work. This means data from RKI, especially case counts and incidences of infectious diseases, can readily be displayed.

Scripts

grid_cartogram_germany.R reads the original shape files. If compute_grids is TRUE, different seeds are tried for each region (either all of Germany at the state level, or for each state at the county/district level). The resulting shapes are saved and compared in a plot, e.g. for Berlin districts:

Berlin districts

One can then explore the plots and chose which seeds produce the best results. Those are then entered in chosen_seeds to copy the corresponding shapes in out/chosen_grids/. Results are stored as list in the file out/chosen_units_grid_l.rds.

For all of Germany at the county level, the grids of individual states are arranged so as to remain readable and get more realistic positioning of the counties. If compute_grids is FALSE the script jumps to this step.

shrink_factor gives of how much state area should be shrunk (the final area is 1-shrink_factor times the original). This makes arranging the grids so they don't overlap while keep geographical distribution easier. One can set the position of each state relative to its geographical centroid with shift_factor. It approximately shifts the state by shift_factor[1] cells to the East and shift_factor[2] to the North-East. The result is displayed to help adjust the shift factors:

German counties and Berlin districts

The illustrations with random data at the beginning are produced by vignette/vignette.Rmd. They can be seen together with code in vignette/vignette.html.

Session information

The shapes and plots were produced with:

R version 3.6.1 (2019-07-05)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: OS X El Capitan 10.11.6

Matrix products: default
BLAS:   /System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets 
[6] methods   base     

other attached packages:
[1] rmapshaper_0.4.4   stringi_1.4.3      here_0.1          
[4] dplyr_0.8.3        RColorBrewer_1.1-2 ggplot2_3.2.1     
[7] patchwork_1.0.0    sf_0.8-1           geogrid_0.1.1     

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2         pillar_1.4.2       compiler_3.6.1    
 [4] class_7.3-15       tools_3.6.1        digest_0.6.21     
 [7] jsonlite_1.6       tibble_2.1.3       gtable_0.3.0      
[10] lattice_0.20-38    pkgconfig_2.0.3    rlang_0.4.0       
[13] DBI_1.0.0          rstudioapi_0.9.0   crul_0.9.0        
[16] curl_4.2           yaml_2.2.0         geojson_0.3.2     
[19] geojsonio_0.9.0    e1071_1.7-0.1      jqr_1.1.0         
[22] withr_2.1.2        rgeos_0.5-2        geojsonlint_0.4.0 
[25] classInt_0.4-2     rprojroot_1.3-2    grid_3.6.1        
[28] tidyselect_0.2.5   jsonvalidate_1.1.0 httpcode_0.2.0    
[31] glue_1.3.1         R6_2.4.0           foreign_0.8-71    
[34] sp_1.4-1           purrr_0.3.2        magrittr_1.5      
[37] maptools_0.9-9     scales_1.0.0       backports_1.1.4   
[40] units_0.6-5        assertthat_0.2.1   colorspace_1.4-1  
[43] V8_3.0.1           KernSmooth_2.23-15 lazyeval_0.2.2    
[46] munsell_0.5.0      crayon_1.3.4  

Contributions

Author: Stéphane Ghozzi

Funding: project Signale of the Robert Koch Institute

Licence

The code and the grid cartograms are made available under a CC0 licence, i.e. others may freely build upon, enhance and reuse the works for any purposes without restriction under copyright or database law. The shape files of German states and counties were constructed from shapes provided by the BKG under the dl-de/by-2-0 licence.

About

Grid cartograms for Germany

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors