The sugarbag package creates tesselated hexagon maps for visualising geo-spatial data. Hexagons of equal size are positioned to best preserve relationships between individual areas and the closest focal point, and minimise distance from their actual location. This method allows all regions to be compared on the same visual scale, and provides an alternative to cartograms.

Maps containing regions with a few small and densely populated areas are extremely distorted in cartograms. An example of this is a population cartogram of Australia, which distorts the map into an unrecognisable shape. The technique implemented in this package is particularly useful for these regions.

Installation

You can install the released version of sugarbag from CRAN with:

You can install the development version from GitHub using:

Getting started

Refer to pkgdown site: https://srkobakian.github.io/sugarbag/

We will use the eechidna package for Australian electorates and election data.

library(sugarbag)
library(eechidna)

The create_centroids function may have been used to find centroid for each area. Instead we use the eechidna package. This has been derived already and is stored in nat_data16.

The sugarbag package operates by creating a grid of possible hexagons to allocate electorates. The buffer extends the grid beyond the geographical space, this is especially useful for densely populated coastal areas or cities, such as Brisbane and Sydney.

# Create a grid of hexagons to allocate centroids
grid <- create_grid(centroids = centroids, hex_size = 0.9, buffer_dist = 5)

The two key pieces, the centroids and the grid can be used by the allocate function.

New England was located quite far from the focal point. Due to this it was placed in an unfortunate position. We can find where we would like to place it by finding neighbouring electorates and looking at their hexagon locations.

# Move hexagons if not placed in desirable hexagon tile
hex_allocated <- hex_allocated %>% mutate(hex_long = ifelse(elect_div == "NEW ENGLAND", 150.6779 + 0.45, hex_long),
  hex_lat = ifelse(elect_div == "NEW ENGLAND", -30.31636 +0.9, hex_lat))

The function fortify_hexagon assists in plotting. We now have 6 points per region, one for each point of a hexagon. Connecting these points will allow actual hexagons to be plotted.

The additional demographic information or data can now be added. This can be used to allow plots to be coloured by region.

For animations to move between geography and hexagons the sf_id must match, there also needs to be an identifier to separate the states to animate between for gganimate.

Here we show the two sets of areas they can be plotted separately using geom_facet.

We can move between the two plots using the transition_states function from the gganimate package.