标签: r2d3

使用 r2d3 在 d3.js 中使用 R data.frame 对象

我试图了解如何使用包将 R 数据框传递给 d3.js 脚本r2d3。扩展r2d3条形图示例以访问data.frame对象中的变量会有所帮助。

代码:

library(r2d3)
data <- data.frame(nums = c(0.3, 0.6, 0.8, 0.95, 0.40, 0.20))
r2d3(data, script = "test.js")
Run Code Online (Sandbox Code Playgroud)

js代码:

var barHeight = Math.floor(height / data.length);

svg.selectAll('rect')
  .data(data.nums)
  .enter().append('rect')
    .attr('width', function(d) { return d * width; })
    .attr('height', barHeight)
    .attr('y', function(d, i) { return i * barHeight; })
    .attr('fill', 'steelblue');
Run Code Online (Sandbox Code Playgroud)

错误:

Error: svg.selectAll(...).data(...).enter is not a function in (test.js#5:4)
TypeError: svg.selectAll(...).data(...).enter is not a function
Run Code Online (Sandbox Code Playgroud)

r d3.js r2d3

5
推荐指数
1
解决办法
559
查看次数

R2D3 与 D3.js 相比

我想在 R 中使用R2D3 pacakge,但不确定这个包与 D3.js 库的关系。R2D3 是否以任何方式限制了 D3 的功能?我们可以在 R2D3 中使用 R 中的所有 D3 函数和特性吗?

r d3.js r2d3

3
推荐指数
1
解决办法
302
查看次数

标签 统计

d3.js ×2

r ×2

r2d3 ×2