How to change ranges and color of bubble legend in R Highcharter?

62 Views Asked by At

I am making a bubble charter with Highcharter in R. But I haven't manage to modify the color of the bubble size legend or the ranges of the bubble sizes that are displayed in the legend, i.e. I haven't been able to translate the Javascript syntax here into R. For example, in the illustrative chart below, change the blue color of the bubble legend to black and change the displayed sizes from 214, 7506.5, and 14799 to 1000, 7000, and 14000.

enter image description here Here is the code for the simple example chart above:

mydata <- tibble(x=sample(seq(1,30,1), 30, replace=T), 
                 y=sample(seq(1,150,1), 30, replace=T),
                 group=sample(seq(1,3,1), 30, replace=T),
                 size=sample(seq(1,15000,1), 30, replace=T))

hchart(mydata, type = "bubble", 
       hcaes(x = x, y = y, size = size, color = group), maxSize = "10%",
       showInLegend = F) %>%
  hc_legend(bubbleLegend = list(enabled = T))

I would really appreciate your help.

1

There are 1 best solutions below

0
On

Below you can find an example of this demo in R: https://jsfiddle.net/BlackLabel/x5kLracd/

As you can see, the legend works correctly there. I hope this configuration will make your work easier!

library(highcharter)

highchart() %>%
  hc_chart(type = "bubble") %>%
  hc_legend(
    enabled = TRUE,
    align = 'left',
    layout = 'vertical',
    verticalAlign = 'top',
    itemMarginTop = 10,
    bubbleLegend = list(
      enabled = TRUE,
      borderWidth = 1,
      connectorDistance = 40,
      maxSize = 70,
      ranges = list(list(), list(), list(color = '#e4d354'))
    )
  ) %>%
  hc_plotOptions(
    series = list(
      maxSize = 70
    )
  ) %>%
  hc_add_series(
    data = list(
      list(x = 95, y = 95, z = 834),
      list(x = 86.5, y = 102.9, z = 1000),
      list(x = 80.8, y = 91.5, z = 242),
      list(x = 80.4, y = 102.5, z = 121)
    )
  ) %>%
  hc_add_series(
    data = list(
      list(x = 80.3, y = 86.1, z = 358),
      list(x = 78.4, y = 70.1, z = 450),
      list(x = 74.2, y = 68.5, z = 598)
    )
  ) %>%
  hc_add_series(
    data = list(
      list(x = 73.5, y = 83.1, z = 678),
      list(x = 71, y = 93.2, z = 314),
      list(x = 69.2, y = 57.6, z = 415),
      list(x = 68.6, y = 20, z = 799)
    )
  ) %>%
  hc_add_series(
    data = list(
      list(x = 65.5, y = 126.4, z = 35.3),
      list(x = 65.4, y = 50.8, z = 28.5),
      list(x = 63.4, y = 51.8, z = 15.4),
      list(x = 64, y = 82.9, z = 31.3)
    )
  )