Question

This gives me a plot and displays in on IPython:

from rpy2.robjects import pandas2ri
pandas2ri.activate()
from rpy2.robjects.lib import ggplot2
from rpy2.interactive import ipython
from pandas import DataFrame

dataf = DataFrame({"x":[1,4,5,2,4.5,3],"y":[3,2,6,2,4,2.1]})

p = ipython.ggplot(dataf) + \
    ggplot2.aes_string(x = 'x', y = 'y') + \
    ggplot2.geom_point() + \
    ggplot2.geom_smooth(method = "loess")
p.png()

Now how do I save the plot to, say, pdf? In other words, is there an Rpy2 mapping for this?

ggsave(filename="x.pdf", plot=x, width=200, height=120, unit='mm')
Was it helpful?

Solution

Try this:

from rpy2 import robjects
robjects.r.ggsave(filename="x.pdf", plot=p, width=200, height=120, unit='mm')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top