0

Can someone help me make the equivalent of this card with the highcharter package ?
There are not too many indications in the documentation...

https://www.highcharts.com/maps/demo/data-class-ranges

Many thanks in advance !

Damien Dotta
  • 771
  • 3
  • 13

2 Answers2

1

You can do this with the helper function built-in to HighChater:

library(tidyverse)
library(viridis)
library(highcharter)

mapdata <- get_data_from_map(download_map_data("countries/us/us-all"))
set.seed(1234)

data_fake <- mapdata %>% 
  select(code = `hc-a2`) %>% 
  mutate(value = 1e5 * abs(rt(nrow(.), df = 10)))

color_classes(c(0, 100000, 200000, 500000))

hcmap("countries/us/us-all", data = data_fake, value = "value",
      joinBy = c("hc-a2", "code"), name = "Fake data",
      dataLabels = list(enabled = TRUE, format = '{point.name}'),
      borderColor = "#FAFAFA", borderWidth = 0.1,
      tooltip = list(valueDecimals = 2, valuePrefix = "$", valueSuffix = " USD")
      ) %>% 
  hc_colorAxis(
    minColor = "gray",
    maxColor = "yellow",
    dataClasses = color_classes(c(0, 100000, 200000, 500000))
  )

The important part is that color_classes list. In this example I have 3 segments made (0-100k, 100k-200k, and 200k-500k). You can set the colors themselves for those in the color array or by some other means.

wergeld
  • 14,332
  • 8
  • 51
  • 81
  • Thank you so much @wergeld ! It works like a charm ! Could you give me the link to the documentation to set colors, the shape and eventually the shape of the legend ? – Damien Dotta May 07 '20 at 17:13
  • 1
    @DamienDotta the documentation is installed when you install the package. You can view it in RStudio if you click on a package name in the Packages tab (in the same window area where Files, Plots, Help, and Viewer are - for me it is the lower right). Here is a link to the CRAN PDF of the documentation: https://cran.r-project.org/web/packages/highcharter/highcharter.pdf – wergeld May 08 '20 at 11:36
  • I tried to use your code with my own data but there's a problem with bubbleLegend : https://stackoverflow.com/questions/61771876/highcharts-mapbubble-display-3-times – Damien Dotta May 13 '20 at 10:17
1

You can find more examples on the official Highcharter website here: http://jkunst.com/highcharter/highmaps.html

These refer to JavaScript, but you can use almost all of them in R: All the Highcharts API properties you can find here: https://api.highcharts.com/highcharts/ and more docs (including colorAxis) you can find here: https://www.highcharts.com/docs/index

raf18seb
  • 2,096
  • 1
  • 7
  • 19
  • Thanks @raf18seb ! I tried to use this properties in R but I still need a little help here : https://stackoverflow.com/questions/61680074/customize-bubble-map-with-highcharter – Damien Dotta May 08 '20 at 19:16
  • I'm assigned to your ticket, didnt have time today, sorry. I'll look at it tomorrow ;) – raf18seb May 08 '20 at 21:48
  • Thank you in advance, if you ever find a solution, I'm really interested – Damien Dotta May 09 '20 at 13:18