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.
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.
Are you interested in having your package included in our feature wall? Send the image of your package hex sticker to [email protected] We will make a big banner from the hex images provided for useR! 2018! #rstats— useR!2018 (@useR2018_conf) May 24, 2018
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.
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)
- Arrange the stickers on the canvas
For more details on using magick to arrange hexagons, you can read arranging hex stickers in R
Creating the hex map
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 raster package.
library(tidyverse) library(raster) library(sf) aus <- getData("GADM", country = "AUS", level = 0) %>% disaggregate() %>% geometry() ggplot() + geom_sf(data = st_as_sf(aus))
To convert this map into hexagonal coordinates, we can use the
spsample function to sample a hexagonal lattice. 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.
hex_points <- aus %>% spsample(type = "hexagonal", cellsize = 2) as_tibble([email protected])
#> # A tibble: 201 x 2 #> x y #> <dbl> <dbl> #> 1 146. -43.3 #> 2 145. -41.6 #> 3 147. -41.6 #> 4 141. -38.1 #> 5 143. -38.1 #> 6 145. -38.1 #> 7 147. -38.1 #> 8 140. -36.4 #> 9 142. -36.4 #> 10 144. -36.4 #> # … with 191 more rows
To ensure that we are happy with the hexagon placements, we should view the hexagon grid on a map. We can convert our coordinates to hexagonal polygons using
HexPoints2SpatialPolygons, and then plot them on the map.
aus_hex <- HexPoints2SpatialPolygons(hex_points, dx = 2) ggplot() + geom_sf(data = st_as_sf(aus)) + geom_sf(data = st_as_sf(aus_hex), colour = "blue", fill = NA)
Looks great, let’s make the map. Using the script from mitchelloharawild/hexwall, we provide:
- A folder containing the hexagon images
- Desired pixel width of each hexagon
- Hexagon coordinates computed above
If there are lot of stickers to position, or the resulting image dimension is large, this may take some time.
source("hexwall.R") hexwall( "hexstickers", sticker_width = 500, coords = [email protected], sort_mode = "colour" )
Beyond that, there were just a few finishing touches needed to add the useR! 2018 logo and text. Hope you all enjoy the 2018 useR! conference :)