Question

I am working with rpy2 v2.1.9 in Python3.2, I don't understand why I can't use the library ggplot2

import rpy2
from rpy2.robjects import r
r.library("ggplot2")

Here is the error message I got

Error in function (package, help, pos = 2, lib.loc = NULL, character.only = FALSE,  : 
  there is no package called 'ggplot2'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.2/dist-packages/rpy2/robjects/functions.py", line 82, in __call__
     return super(SignatureTranslatedFunction, self).__call__(*args, **kwargs)
   File "/usr/local/lib/python3.2/dist-packages/rpy2/robjects/functions.py", line 34, in __call__
     res = super(Function, self).__call__(*new_args, **new_kwargs)
 rpy2.rinterface.RRuntimeError: Error in function (package, help, pos = 2, lib.loc = NULL, character.only = FALSE,  : 
   there is no package called 'ggplot2'
Was it helpful?

Solution

See the tail of the first error message:

there is no package called 'ggplot2'

You need to install the ggplot2 package first. Fire up R itself, and say

 install.packages("ggplot2")
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top