문제

I use the following code fragment to plot a pandas dataframe with ggplot in ipython notebook.

%%R -i data
plot = ggplot(data) + geom_line(aes(x=x, y=y))
print(plot)

The result is the expected plot in png format. I would like to have an svg image instead, but I just cannot figure out how this can be done.

도움이 되었습니까?

해결책

In previous versions of rpy2 my proposed solution did not work. However with rpy2-2.4.3 the following now works as expected:

%load_ext rpy2.ipython 
%R require(ggplot2)
%Rdevice svg

After setting up R, the plotting works as expected and the shown plot will be in svg format.

Create data as a pandas DataFrame in python:

import pandas as pd
data = pd.DataFrame({"x":[1,2,3], "y": [3,2,1]})

And finally do the plotting:

%%R -i data
plot = ggplot(data) + geom_line(aes(x=x, y=y))
print(plot)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top