This document details ahow to work with Uber’s h3. In globe4r there are two ways to approach the latter:
The latter provides much more control and intuition about the visualisation, the former much less so but is much easier to put together, see example below.
quakes %>% create_globe() %>% globe_hex( coords(lat, long) ) %>% globe_pov(-15, 160) # position camera
There a few packages that will let you “bin” your data in to Uber’s h3 hexagons from R:
Feel free to use any of the above, the point of this excercise is simply to bin into hexagons and then use the coordinates of the center of said hexagons in globe4r, however since I authored the last of those packages (for this very purpose) I will use it for this example.
We can compute the “h3index”, the index of the hexagon where our coordinates are located.
Then we can aggregate our data over the h3index, i.e.: with the
tidyverse, i.e.: below counting the number of observed earthquakes by hexagon.
Then re-compute the center of each hexagon.
Then we can plot the hexagons, note that we set the
n in the
coords function, when omitted it defaults to
h3index %>% create_globe() %>% globe_hex( coords(hex_center_lat, hex_center_lon, weight = n) ) %>% globe_pov(-15, 160) # position camera
Thanks to computing those on the R side we know the range of the \(n\) aggregated in the hexagon, which enables computing color and height range.
This will help us compute the color with