rCharts - Highcharts气泡图的数据标签

时间:2016-02-24 08:15:53

标签: r highcharts rcharts bubble-chart

我使用rCharts创建Highcharts气泡图,但无法更改气泡标签。在此示例中,我希望分支名称显示在气泡中而不是默认y。样本数据和我使用的代码:

branch <- c('A', 'B', 'C', 'D', 'E', 'F')
cases <- c('100', '200', '300', '400', '500', '600')
prop <- c('600', '500', '400', '300', '200', '100')
units <- c('6', '5', '4', '3', '2', '1')
size <- c('large', 'large', 'large', 'medium', 'small', 'small')
df <- data.frame(branch, cases, prop, units, size)

library(rCharts)

h1 <- hPlot(x = "prop", y = "units", data = df, type = "bubble", group = "size", size = "cases", name = "branch")

h1$plotOptions(bubble =list(dataLabels = list(enabled = TRUE, x = 0,
                                          formatter = "#! function() {
                                          return this.point.name;} !#"
                                          )))

感谢所有帮助!谢谢!

1 个答案:

答案 0 :(得分:0)

hPlot中无法在toolTip或plotOptions中使用未使用的colomn。

尝试使用以下代码,而不是使用名称Y:

branch <- c('A', 'B', 'C', 'D', 'E', 'F')
cases <- c(100, 200, 300, 400, 500, 600)
prop <- c(600, 500, 400, 300, 200, 100)
units <- c(6, 5,4, 3, 2, 1)
size <- c('large', 'large', 'large', 'medium', 'small', 'small')
df <- data.frame(branch, cases, prop, units, size)

library(rCharts)

h1 <- hPlot(x = "prop", y = "units", type = "bubble", group = "size", size = "cases", name = "branch", data = df)

h1$plotOptions(series=list(dataLabels=list(enabled=TRUE, format = '{y}')))

h1

正如您所见,这将显示气泡中的y值。您也可以显示x值。但就是这样。这是由于气泡图的结构。但是有一个解决方法。有关详细信息,请参阅https://github.com/ramnathv/rCharts/issues/289