0

这给了我一个绘图并在 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()

现在我如何将情节保存为pdf?换句话说,是否有一个 Rpy2 映射?

ggsave(filename="x.pdf", plot=x, width=200, height=120, unit='mm')
4

1 回答 1

1

尝试这个:

from rpy2 import robjects
robjects.r.ggsave(filename="x.pdf", plot=p, width=200, height=120, unit='mm')
于 2013-11-01T21:33:44.640 回答