Learn R Programming

highcharter (version 0.3.0)

hc_add_series_map: Shorcut for create map

Description

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

Usage

hc_add_series_map(hc, map, df, value, joinBy, ...)
hc_add_serie_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

Run this code

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.parse3(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)
  

Run the code above in your browser using DataLab