0

我有下面的代码和情节

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")

在此处输入图像描述

对于图例,目前是“系列 1”,我想为每个点颜色制作点图例,即绿色、橙色和红色。并且还自定义图例文本。

图例应如下所示:

(红点) 20% 分位数 (绿点) 40% 分位数 (橙点) 80% 分位数

4

1 回答 1

3

使用人工(空)系列创建图例条目:

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")

在此处输入图像描述

于 2017-11-29T23:50:46.847 回答