rPlot工具提示问题

时间:2014-01-05 02:05:53

标签: r rcharts

我有一个使用rCharts工具提示的简单示例,似乎不起作用:

set.seed(1)
test <- data.frame(x = rnorm(100), y = rnorm(100))
rPlot(y ~ x, data = test, 
      type = 'point',
      tooltip = "function(item){return item.x + '\n' + item.name + '\n' + item.y}") 

出现一个空白页面。如果我删除了工具提示选项,那么该图就在那里。我正在使用rCharts_0.4.1,R正在开发x86_64-apple-darwin10.8.0(64位)和版本31.0.1650.63的Chrome。

加分问题!工具提示可以包含数据集中的变量,但未在xy等中使用吗?我有一个大型数据集,我想使用每行具有唯一值的ID变量来注释数据点。

谢谢,

最高

2 个答案:

答案 0 :(得分:4)

Rcharts 0.4.2

我不能指出我之前看过的地方,但我能提供的最好的是当前的指令是如此包装你的js函数:

"#!function(item) { return item.x }!#"

set.seed(1)
test <- data.frame(x = rnorm(100), y = rnorm(100), id = 1:100)
p <- rPlot(y ~ x, data = test, 
        type = 'point',
        tooltip = "#!function(item){ return 'x: ' + item.x + 
        ' y: ' + item.y + ' id: ' + item.id }!#")

我永远无法获得不同线路的提示。您可以通过在创建工具提示时键入p$show('inline')并在其中包含换行符来查看问题。 Mustache正在转换换行符,这意味着它们会在生成的JS函数中消失,并导致工具提示函数跨越多行 - 导致错误。我试图逃避换行符并附加包含换行符.replace('\\n', '\n')的每个字符串,但这显然会导致同样的问题。

目前,最好的办法是制作如此处所示的情节,输入p$save('filepath.html')并手动添加换行符。否则,问题是如何将文字换行符传递给小胡子。

答案 1 :(得分:0)

您的代码使用rCharts 0.3.51(Chrome 31.0.1650.63 m,Win7 x64)工作/工作:

set.seed(1)
require(rCharts)
test <- data.frame(x = rnorm(100), y = rnorm(100), 
                   name=replicate(100, paste(sample(letters, 5, rep=T), collapse="")))
rPlot(y ~ x, data = test, 
      type = 'point',
      tooltip = "function(item){return item.x + '\n' + item.name + '\n' + item.y}")

您应该可以引用test中的所有列 - 就像我对name所做的那样。

enter image description here

相关问题