gpt4 book ai didi

r - nvd3 scatterPlot 与 R 中的 rCharts : Vary size of points?

转载 作者:行者123 更新时间:2023-12-04 09:50:10 25 4
gpt4 key购买 nike

我一直在玩 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

是否可以?

最佳答案

可以使用 chart方法,它允许您指定 size , color等等。现在的实现有点笨拙,需要您传递一个 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

NVD3 Chart with Size

关于r - nvd3 scatterPlot 与 R 中的 rCharts : Vary size of points?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19421211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com