View source: R/geom_sugarbag.R
geom_sugarbag | R Documentation |
geom_sugarbag()
provides a convenient way to create tesselated
hexagon maps using the sugarbag algorithm.
geom_sugarbag(
mapping = NULL,
data = NULL,
stat = "sugarbag",
position = "identity",
hex_size = 0.2,
na.rm = FALSE,
...
)
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
stat |
The statistical transformation to use on the data for this
layer, either as a |
position |
Position adjustment, either as a string naming the adjustment
(e.g. |
hex_size |
Default is 0.2. Units are degrees, corresponding to
the diameter of the hexagons. See |
na.rm |
If |
... |
Other arguments passed on to |
Create a sugarbag hex map
The sugarbag algorithm creates a hexagon tile map from spatial polygons. It represents each polygon with a hexagon, which is placed close to the polygon's centroid while also maintaining its spatial relationship to a focal point.
If geom_sugarbag()
is used to make a map of Australia, the capital cities
will be used as focal points. For non-Australian maps, a single focal point
will be inferred from the data, as the centroid with the smallest total
distance to its three nearest neighbours. To specify focal points manually,
construct your hexagon grid manually – see ?allocate
.
allocate, ggplot2::geom_polygon
library(ggplot2)
# Map of Tasmanian local govt areas using built-in data
tas_lga %>%
ggplot(aes(fill = lga_name_2016)) +
geom_sf(alpha = 0.1) +
geom_sugarbag(aes(geometry = geometry)) +
theme(legend.position = "none")
# Map of SIDS data from North Carolina
if (requireNamespace("sf", quietly = TRUE)) {
nc <- sf::st_read(system.file("shape/nc.shp", package = "sf"), quiet = TRUE)
ggplot(nc,
aes(fill = AREA)) +
geom_sf(alpha = 0.1) +
geom_sugarbag(aes(geometry = geometry))
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.