Skip to contents

Add a map series

Usage

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 variable to chart.

joinBy

What property to join the map and df

...

Additional shared arguments for the data series (https://api.highcharts.com/highcharts/series).

Details

This function force the highchart object to be map type.

Examples


library("dplyr")
#> 
#> ######################### Warning from 'xts' package ##########################
#> #                                                                             #
#> # The dplyr lag() function breaks how base R's lag() function is supposed to  #
#> # work, which breaks lag(my_xts). Calls to lag(my_xts) that you type or       #
#> # source() into this session won't work correctly.                            #
#> #                                                                             #
#> # Use stats::lag() to make sure you're not using dplyr::lag(), or you can add #
#> # conflictRules('dplyr', exclude = 'lag') to your .Rprofile to stop           #
#> # dplyr from breaking base R's lag() function.                                #
#> #                                                                             #
#> # Code in packages is not affected. It's protected by R's namespace mechanism #
#> # Set `options(xts.warn_dplyr_breaks_lag = FALSE)` to suppress this warning.  #
#> #                                                                             #
#> ###############################################################################
#> 
#> Attaching package: ‘dplyr’
#> The following objects are masked from ‘package:xts’:
#> 
#>     first, last
#> The following objects are masked from ‘package:stats’:
#> 
#>     filter, lag
#> The following objects are masked from ‘package:base’:
#> 
#>     intersect, setdiff, setequal, union

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

USArrests <- mutate(USArrests, state = rownames(USArrests))

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 = color_stops()) |>
  hc_legend(valueDecimals = 0, valueSuffix = "%") |>
  hc_mapNavigation(enabled = TRUE)
if (FALSE) { # \dontrun{ data(worldgeojson, package = "highcharter") data("GNI2014", package = "treemap") highchart(type = "map") |> hc_add_series_map(map = worldgeojson, df = GNI2014, value = "GNI", joinBy = "iso3") |> hc_colorAxis(stops = color_stops()) |> hc_tooltip( useHTML = TRUE, headerFormat = "", pointFormat = "this is {point.name} and have {point.population} people with gni of {point.GNI}" ) } # }