I am trying to run this code in a Jupyter notebook
# Hide warnings if there are any
import warnings
warnings.filterwarnings('ignore')
# Load in the r magic
%load_ext rpy2.ipython
# We need ggplot2
%R require(ggplot2)
# Load in the pandas library
import pandas as pd
# Make a pandas DataFrame
df = pd.DataFrame({'Alphabet': ['a', 'b', 'c', 'd','e', 'f', 'g', 'h','i'],
'A': [4, 3, 5, 2, 1, 7, 7, 5, 9],
'B': [0, 4, 3, 6, 7, 10, 11, 9, 13],
'C': [1, 2, 3, 1, 2, 3, 1, 2, 3]})
# Take the name of input variable df and assign it to an R variable of the same name
%R -i df
# Plot the DataFrame df
ggplot(data=df) + geom_point(aes(x=A, y=B, color=C))
After running this code I get the error NameError: name 'ggplot' is not defined
In fact, when I run %R require(ggplot2)
I get an empty array: array([0], dtype=int32)
UPDATE
After @James comment, if I use %R ggplot(data=df) + geom_point(aes(x=A, y=B, color=C))
instead of ggplot(data=df) + geom_point(aes(x=A, y=B, color=C))
then I get Error in ggplot(data = df) : could not find function "ggplot"