基于点颜色的R highcharter图例
R highcharter legend based on point color
我有下面的代码和情节
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")
对于图例,目前是"Series 1",我想为每个点颜色制作点图例,即绿色、橙色和红色。并自定义图例文本。
图例应如下所示:
(红点)20%分位数(绿点)40%分位数(橙点)80%分位数
使用人工(空)系列创建图例条目:
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")
我有下面的代码和情节
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")
对于图例,目前是"Series 1",我想为每个点颜色制作点图例,即绿色、橙色和红色。并自定义图例文本。
图例应如下所示:
(红点)20%分位数(绿点)40%分位数(橙点)80%分位数
使用人工(空)系列创建图例条目:
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")