2013-11-01 59 views
0

這使我對IPython中的情節,並顯示:保存rpy2.robjects.lib.ggplot2

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') 

回答

1

試試這個:

from rpy2 import robjects 
robjects.r.ggsave(filename="x.pdf", plot=p, width=200, height=120, unit='mm')