-
Notifications
You must be signed in to change notification settings - Fork 0
/
geoviz_hexagonal-choropleth.Rmd
62 lines (46 loc) · 2.33 KB
/
geoviz_hexagonal-choropleth.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
---
title: "Charts: Hexagonal Choropleth"
output:
html_document:
toc: true
toc_float:
collapsed: false
includes:
before_body: [includes/include_header.html, includes/include_header_navpage.html]
editor_options:
chunk_output_type: console
---
## What is a hexagonal choropleth (or a tilegram)?
Hexagonal Choropleth are choropleth where regions are converted into equally sized hexagons and each is coloured according to either a discrete or continuous variable. More generally these visualisations are called <strong>tilegrams</strong>, where the regions can be any <em>regular polygon</em> but hexagons are amongst one of the most flexible shapes for these maps. The process of converting shapefiles to regular polygons that are positioned in such a way to still retain the shape of the original geographic regions is complicated, and typically requires manual hand tuning.
Required Data:
- Hexagonal Regions: Enclosed hexagonal regions, i.e. topologically closed polygons, sometimes called convex hulls. For instance the subregions within a country, i.e. the states of the USA.
- Values: Discrete or categorical values for each enclosed region, for instance the population of each state or the division to which the state belongs.
Below is a minimal example of a hexagonal choropleth built using `R` and the `leaflet` library, inspired by this [tutorial on `tilegramsR`](http://rpubs.com/bhaskarvk/tilegramsR)
```{r, echo=FALSE, message=FALSE, warning=FALSE, paged.print=FALSE}
library("tilegramsR")
library("leaflet")
library("sf")
library("statesRcontiguous")
library("tidyverse")
states_info <- shp_all_us_states
st_geometry(states_info) <- NULL
NPR1to1 <- st_as_sf(NPR1to1) %>%
left_join(states_info, by = c("state" = "state.short.name"))
palette_state_division <- colorFactor("Paired", unique(NPR1to1$state.division))
leaflet(
NPR1to1,
options=leafletOptions(
crs = leafletCRS("L.CRS.Simple"),
minZoom = -3, maxZoom = -3,
dragging = FALSE, zoomControl = FALSE,
attributionControl = FALSE),
width = "250px", height = "250px"
) %>%
addPolygons(
weight=2,
color='#000000', group = 'states',
fillOpacity = 0.6, opacity = 1, fillColor= ~palette_state_division(state.division),
highlightOptions = highlightOptions(weight = 4),
label = ~paste0(state, " (", state.division, ")")
)
```