【发布时间】:2015-02-06 16:18:18
【问题描述】:
我有一个如下所示的数据框:
## Data
df <- data.frame(label = c("A", "B", "C", "D"),
color = c("red", "red", "blue", "green"),
y = c(10, 11, 12, 13))
“A”和“B”属于同一类别,而“C”和“D”属于不同类别。
我想在图表上添加一个带有类别标签的图例。
## Highchart without Legend
## Basic highchart
h <- rCharts:::Highcharts$new()
h$chart(type = "column")
## Highchart data:
h$series(showInLegend = FALSE, data = rCharts::toJSONArray2(df[, c("label", "color", "y")], json = FALSE, names = TRUE))
## Highchart options:
h$xAxis(categories = unique(df$label), labels = list(rotation = 0, align = 'center', style = list(fontSize = '12px', fontFamily = 'Verdana, sans-serif')), replace = FALSE)
h$tooltip(formatter = "#! function() {return this.x + ': ' + this.y; } !#")
h$plotOptions(series = list(color = df$color), column = list(grouping = FALSE))
h # display highchart
我还没有找到任何有意义的方法来解决这个问题。
任何帮助将不胜感激。
【问题讨论】:
标签: r highcharts rcharts