ggplot2 not present in rpy2 for python?

2019-06-07 11:32发布

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'

1条回答
男人必须洒脱
2楼-- · 2019-06-07 12:07

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")
查看更多
登录 后发表回答