nvd3 scatterPlot with rCharts in R: Vary size of points?

后端 未结 1 1281
眼角桃花
眼角桃花 2020-12-31 21:31

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

相关标签:
1条回答
  • 2020-12-31 21:33

    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 Chart with Size

    0 讨论(0)
提交回复
热议问题