Shorcut for create map

Description

This function helps to create higcharts treemaps from treemap objects from the package treemap.

Usage

1
hc_add_series_map(hc, map, df, value, joinBy, ...)

Arguments

hc

A highchart htmlwidget object.

map

A list object loaded from a geojson file.

df

A data.frame object with data to chart. Code region and value are required.

value

A string value with the name of the column to chart.

joinBy

What property to join the map and df

...

Aditional shared arguments for the data series (http://api.highcharts.com/highcharts#series).

Examples

 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
library("dplyr")
library("viridisLite")

data("USArrests", package = "datasets")
data("usgeojson")

USArrests <- USArrests %>% 
  mutate(state = rownames(.))

n <- 4
colstops <- data.frame(q = 0:n/n,
                       c = substring(viridis(n + 1, option = "A"), 0, 7)) %>% 
list_parse2()

highchart() %>% 
  hc_title(text = "Violent Crime Rates by US State") %>% 
  hc_subtitle(text = "Source: USArrests data") %>% 
  hc_add_series_map(usgeojson, USArrests, name = "Murder arrests (per 100,000)",
                    value = "Murder", joinBy = c("woename", "state"),
                    dataLabels = list(enabled = TRUE,
                                      format = '{point.properties.postalcode}')) %>% 
  hc_colorAxis(stops = colstops) %>% 
  hc_legend(valueDecimals = 0, valueSuffix = "%") %>%
  hc_mapNavigation(enabled = TRUE) 

## Not run: 

library("viridisLite")
library("dplyr")
data(unemployment)
data(uscountygeojson)
 
dclass <- data_frame(from = seq(0, 10, by = 2),
                     to = c(seq(2, 10, by = 2), 50),
                     color = substring(viridis(length(from), option = "C"), 0, 7))
 dclass <- list_parse(dclass)
highchart() %>% 
  hc_title(text = "US Counties unemployment rates, April 2015") %>% 
  hc_add_series_map(uscountygeojson, unemployment,
                    value = "value", joinBy = "code") %>%
  hc_colorAxis(dataClasses = dclass) %>%
  hc_legend(layout = "vertical", align = "right",
            floating = TRUE, valueDecimals = 0,
            valueSuffix = "%") %>%
  hc_mapNavigation(enabled = TRUE)
  

## End(Not run)
  

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.