【问题标题】:is ggplot2.layer fully supported in Rpy2?Rpy2 完全支持 ggplot2.layer 吗?
【发布时间】:2013-02-02 10:53:55
【问题描述】:

我正在尝试在通过 Rpy2 绘制的图表中使用 ggplot2 layer,我没有在手册中看到 (http://rpy.sourceforge.net/rpy2/doc-2.1/html/graphics.html)

调用layer 函数的正确形式是否如下?来自 R,

p <- p + layer(data=df, mapping=aes(x=x, y=y, label=foo), geom='text', hjust=1, vjust=1)

应该在 Rpy2 中:

p += ggplot2.layer(**{"data": df,
                      "mapping": ggplot2.aes_string(x="x", y="y", label="foo"),
                      "geom": "text"})
                      "hjust": 1,
                      "vjust": 1})

当我尝试这个时,我得到如下错误:

TypeError: new() got an unexpected keyword argument 'vjust'

和:

TypeError: new() got an unexpected keyword argument 'mapping'

只是想知道这是否是将layer 添加到 Rpy2 的情节的正确方法,或者是否有不同的习语?谢谢。

【问题讨论】:

  • 你为什么要使用layer,而不是典型的geom_*和stat_*函数?
  • 这是我发现的唯一方法:plt &lt;- qplot(data=iris, x=Sepal.Width, y=Sepal.Length) + facet_wrap(~Species); plt &lt;- plt + layer(data=textdf.a, mapping=aes(x=x, y=y, label=textdf.b), geom='text', hjust=1, vjust=1) 一种注释由此 qplot 调用生成的散点图的方法。我对替代品持开放态度。
  • 提示:完全停止使用qplot,改用ggplot()。 (基本上)永远不要使用layer。总是有一个特定的 geom_* 函数是等效的。在这种情况下,geom_text().
  • 真的没有什么不同:geom_text(data = textdf.a,aes(...),hjust = ...,vjust = ...).
  • @joran,作为答案发帖?

标签: python r ggplot2 rpy2


【解决方案1】:

有不同的方法来做到这一点(在 cmets 中回答)。

除此之外,rpy2 中存在一个错误,无法指定 layer() 的参数参数,现在(希望)在 version_2.3.x(将包含在版本 2.3.3 中)和 default 两个分支中修复。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-21
    • 2017-11-25
    • 2018-01-18
    • 2014-04-20
    • 2017-05-31
    相关资源
    最近更新 更多