【问题标题】:nvd3 scatterPlot with rCharts in R: Vary size of points?R中带有rCharts的nvd3 scatterPlot:改变点的大小?
【发布时间】:2013-10-17 08:00:57
【问题描述】:

我玩 rCharts 和 nvd3 已经有一段时间了。现在我需要一个气泡图,或者至少是一个散点图,其中点的大小取决于数据中的变量。从this example 看来,这似乎是可能的。 rCharts中散点图的例子是:

library(rCharts)
p1 <- nPlot(mpg ~ wt, group = 'cyl', data = mtcars, type = 'scatterChart')
p1$xAxis(axisLabel = 'Weight')
p1

所以我尝试将大小设置为,例如gears。但这并没有改变任何东西。

p2 <- nPlot(mpg ~ wt, group = 'cyl', size = 'gear', data = mtcars, type = 'scatterChart')
p2$xAxis(axisLabel = 'Weight')
p2

有可能吗?

【问题讨论】:

    标签: r nvd3.js rcharts


    【解决方案1】:

    可以使用chart 方法,它允许您指定sizecolor 等。现在的实现有点笨拙,需要您传递一个javascript函数,该函数返回指定的列尺寸。 #! ... !# 语法需要告诉 rCharts 将内容视为 JS 文字,而不是在组装有效负载时将其转换为字符串。图表可以查看here

    library(rCharts)
    p2 <- nPlot(mpg ~ wt, group = 'cyl', data = mtcars, type = 'scatterChart')
    p2$xAxis(axisLabel = 'Weight')
    p2$chart(size = '#! function(d){return d.gear} !#')
    p2
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-16
      相关资源
      最近更新 更多