The hexwall at useR! 2018 features roughly 200 contributed R package hexagon stickers. If you’ve ever had difficulty aligning hexagon stickers in your slides or even on your laptop, you may appreciate the challenge of arranging hundreds of hexagons. Fortunately with R and a little bit of magick, we can substantially simplify this process.
Collection
Hexagon collection proved to be one of the more time-consuming steps in the project. Without a Comprehensive R Hexagon Repository (CRHR), Di Cook (@visnut) and I resorted to collecting hexagons via email and promoting the project via twitter.
Our collection efforts were also supported by Rstudio’s hex-stickers and Bioconductor’s BiocStickers repositories. We opted not to sift through the hexb.in library as we wanted the feature wall to feature only R package stickers.
The response to our project has been huge, and we are grateful for everyone who has contributed their stickers.
hexwall
The hexwall script (available at mitchelloharawild/hexwall) provides the magick for cleaning, sorting, and arranging hexagons. The function does the following operations using the ROpenSci magick package:
Load the images
Make white backgrounds transparent
Trim images
Remove bad images (low resolution or incorrect dimensions)
To create a hexagon map of Australia, we first need to find a map. I’m using the GADM database to give a nice boundary of Australia, which is easily obtainable via the geodata package (the raster package’s getData() used previously has since been removed in favour of geodata).
#> Warning in st_cast.sf(., "POLYGON"): repeating attributes for all
#> sub-geometries for which they may not be constant
# Keep only the mainland and Tasmania, dropping the many tiny offshore# islands so the hexagon tiling reflects Australia's overall shapeaus <- aus[order(st_area(aus), decreasing =TRUE)[1:2]]ggplot() +geom_sf(data =st_as_sf(aus))
To convert this map into hexagonal coordinates, we can use sf::st_make_grid() to lay a hexagonal lattice over the map, keeping only the hexagons that overlap Australia’s outline. Through experimentation, a cellsize of 2 is roughly appropriate for the number of hexagons submitted to us. As it is a random process, some repetition may be needed to get the exact number of hexagons on the map with a nice layout.
The mainland and Tasmania are gridded separately, testing overlap against a slightly eroded outline (st_buffer(land, -0.3)). This trims the hexagons that would otherwise only just clip the coastline, so the tiling doesn’t bridge the Bass Strait gap between the two.