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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With