【问题标题】:accessing shape attribute for points when making NVD3 scatterChart with nplot/rCharts使用 nplot/rCharts 制作 NVD3 散点图时访问点的形状属性
【发布时间】:2013-09-27 19:36:16
【问题描述】:

在使用 rCharts 中的 nplot 构建散点图时,如何设置点的形状属性?可以通过在输入数据框中提供一个名为“size”的列来设置点大小,但如果有一个由“square”或“cross”等字符串组成的相应“shape”列,则结果图仍然具有默认的圆形点。 R 和 NVD3 的新手,所以我为我的词汇量不足道歉。

【问题讨论】:

    标签: r nvd3.js rcharts


    【解决方案1】:

    似乎最新版本的 nvd3 不再像旧版本一样工作。请参阅example。 screenshot 显示形状,数据有shape:,但实际图表中只呈现圆形。此外,tests 不会产生除圆圈以外的任何东西。我看了一眼源,我找不到在哪里或如何设置形状。如果您知道如何使用 nvd3,我可以轻松地将其转换为 rCharts 示例。

    【讨论】:

    • 我看到一个隐藏在 NVD3 深处的参数 onlyCircles 默认设置为 TRUE。所以像n1$chart(onlyCircles = FALSE) 这样的操作应该允许渲染形状。
    【解决方案2】:

    我没有 50 的声望,但我想发表评论。

    this NVD3 example(Novus.github) 中的第 18 行显示了它目前是如何完成的。同样,您需要对live code(nvd3.org) 做的就是取消注释数据选项卡中的“大小”行。

    我尝试在我的 df 中创建一个名为“shape”的列,并使用n1 <- nPlot(x~y, data=df, shape='shape', type='scatterChart'); n1$chart(onlyCircles=FALSE); 和许多其他组合。我只花了最后两天使用 rCharts,但取得了一些令人兴奋的进展。我放弃了这一点,但奇怪的是这里没有提到这两个例子,所以我想我会提到它们。

    【讨论】:

      【解决方案3】:

      我知道这个问题有点“古老”,但我遇到了同样的问题,我花了一段时间才弄清楚如何改变形状。

      我按照此示例中的方法更改大小: nvd3 scatterPlot with rCharts in R: Vary size of points?

      这是我的解决方案:

      library(rCharts)
      df=data.frame(x=rep(0:2,3),y=c(rep(1,3),rep(2,3),rep(3,3)),
      group=c(rep("a",3),rep("b",3),rep("c",3)),shape=rep("square",9))
      
      p <- nPlot(y~x , group = 'group',data = df, type = 'scatterChart')
      
      #In order to make it more pleasant to look at
      p$chart(xDomain=c(-0.5,2.5))
      p$chart(yDomain=c(0,4))
      p$chart(sizeRange = c(200,200))
      
      #here the magic
      p$chart(scatter.onlyCircles = FALSE)
      p$chart(shape = '#! function(d){return d.shape} !#')
      
      p
      

      【讨论】:

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