【发布时间】: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 <- qplot(data=iris, x=Sepal.Width, y=Sepal.Length) + facet_wrap(~Species); plt <- 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,作为答案发帖?