Question

I am trying to use ggplot2 layer in my graph plotted via Rpy2, which I don' see described in the manual (http://rpy.sourceforge.net/rpy2/doc-2.1/html/graphics.html)

Is the correct form for calling the layer function the following? From R,

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

Should be in Rpy2:

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

When I try this, I get errors like:

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

and:

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

Just wondering if this is the correct way to add a layer to a plot from Rpy2, or if there's a different idiom? thanks.

Was it helpful?

Solution

There are different ways to do it (answered in the comments).

Beside that there was a bug in rpy2 preventing parameters parameters to layer() to be specified, now (hopefully) fixed in both branches version_2.3.x (will be included with release 2.3.3) and default.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top