nvd3 scatterPlot 与 R 中的 rCharts:点的大小不同? [英] nvd3 scatterPlot with rCharts in R: Vary size of points?

查看:31
本文介绍了nvd3 scatterPlot 与 R 中的 rCharts:点的大小不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I've been playing with rCharts and nvd3 for a bit of time now. Now I'm in a situation where I need a bubble chart, or at least a scatterplot where the size of the dots is dependent on a variable in the data. From this example, it seems possible. The example on scatter charts in rCharts is:

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

所以我尝试将大小设置为例如 gears.但它不会改变任何东西.

So I've tried setting size to, for example gears. But it doesn't change anything.

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

有可能吗?

推荐答案

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

It is possible using the chart method, which allows you to specify size, color etc. The implementation is a little clunky right now, and requires you to pass a javascript function that returns the column specifying the size. The #! ... !# syntax is required to tell rCharts to treat the contents as a JS literal, and not convert it to a string while assembling the payload. The chart can be viewed 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 scatterPlot 与 R 中的 rCharts:点的大小不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆