0

I have codes and plot below

tmp <- data.frame(x = 1:5, y = rnorm(5),
color = c("#00FF00", "#FF0000", "#00FF00", "#ffa500", "#FF0000"))

highchart() %>%
  hc_add_series(data= tmp, hcaes(x = x, y = y, color = color), type = "line")

enter image description here

For the legend, currently it is "Series 1", I want to make it point legend for each point color, which is Green, Orange, and Red. And also customize the legend text.

Legend should look Like:

(red point) 20% quantile (green point) 40% quantile (orange point) 80% quantile

shosaco
  • 5,915
  • 1
  • 30
  • 48
Z.Lu
  • 67
  • 10
  • To do that you would need to create a series that contains each point you want. The highcharts legend color is for the series - not by point. – wergeld Nov 29 '17 at 20:08

1 Answers1

3

Using artificial (empty) series for creating the legend entries:

highchart() %>%

   # add the series and exclude it from the legend
   hc_add_series(data = tmp, type = "line", showInLegend = F) %>% 

   # add three empty series for the legend entries. Change color and marker symbol
   hc_add_series(data = data.frame(), name = "20% Quantile", color = "#FF0000", marker = list(symbol = "circle"), type = "scatter") %>% 
   hc_add_series(data = data.frame(), name = "40% Quantile", color = "#00FF00", marker = list(symbol = "circle"), type = "scatter") %>% 
   hc_add_series(data = data.frame(), name = "80% Quantile", color = "#ffa500", marker = list(symbol = "circle"), type = "scatter")

enter image description here

shosaco
  • 5,915
  • 1
  • 30
  • 48