无法在RStudio上安装和加载ggplot2

时间:2018-01-31 10:06:09

标签: r ggplot2 rstudio

我尝试先使用ggplot2安装install.packages("ggplot2"),但在我尝试使用库("ggplot2")打开后,它会向我显示以下错误消息:

library ('ggplot2')
  

库中的错误(“ggplot2”):没有名为'ggplot2'的包

这是因为我试图在Mac或RStudio而不是R上运行它吗?我怎样才能安装它?

这些是我正在使用的版本的详细信息:

RStudio版本0.99.902 - ©2009-2016 RStudio,Inc。 Mozilla / 5.0(Macintosh; Intel Mac OS X 10_12_6)AppleWebKit / 604.4.7(KHTML,像Gecko

非常感谢任何帮助!

以下是我尝试将 ggplot 安装为软件包时获得的内容,如果它有帮助...

> install.packages("ggplot2")
Installing package into ‘/Users/crystlewee/Library/R/3.2/library’
(as ‘lib’ is unspecified) also installing the dependency ‘scales’

There are binary versions available but the source versions are later:
  binary source needs_compilation
scales   0.4.0  0.5.0              TRUE
ggplot2  2.1.0  2.2.1             FALSE
Do you want to install from sources the package which needs compilation?
y/n: y
installing the source packages ‘scales’, ‘ggplot2’
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                               Dload  Upload   Total   Spent    Left  Speed
0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0  0 59867    0     0    0     0      0      0 --:--:--  0:00:01 --:--:--     0100 59867  100 59867    0     0  39753      0  0:00:01  0:00:01 --:--:-- 39752
% Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                               Dload  Upload   Total   Spent    Left  Speed
0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0  0     0    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0 16 
* installing *source* package ‘scales’ ...
** package ‘scales’ successfully unpacked and MD5 sums checked
** libs
llvm-g++-4.2 -arch x86_64 -I/Library/Frameworks/R.framework/Resources/include -DNDEBUG  -I/usr/local/include -I"/Users/crystlewee/Library/R/3.2/library/Rcpp/include"   -fPIC  -mtune=core2 -g -O2  -c RcppExports.cpp -o RcppExports.o
/bin/sh: llvm-g++-4.2: command not found
make: *** [RcppExports.o] Error 127
ERROR: compilation failed for package ‘scales’
* removing ‘/Users/crystlewee/Library/R/3.2/library/scales’
* restoring previous ‘/Users/crystlewee/Library/R/3.2/library/scales’
Warning in install.packages :
installation of package ‘scales’ had non-zero exit status
* installing *source* package ‘ggplot2’ ...
** package ‘ggplot2’ successfully unpacked and MD5 sums checked
** R
** data
*** moving datasets to lazyload DB
** inst
** preparing package for lazy loading
Error in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]) : 
namespace ‘scales’ 0.4.0 is being loaded, but >= 0.4.1 is required
ERROR: lazy loading failed for package ‘ggplot2’
* removing ‘/Users/crystlewee/Library/R/3.2/library/ggplot2’
Warning in install.packages :
installation of package ‘ggplot2’ had non-zero exit status

The downloaded source packages are in
‘/private/var/folders/my/vqvl_d89237fcc75nv24lqxw0000gn/T/Rtmpv0MgCR/downloaded_packages’

1 个答案:

答案 0 :(得分:1)

您收到的第一条错误消息是编译scales

/bin/sh: llvm-g++-4.2: command not found

我对C ++一无所知,但g ++是一个C ++编译器。 ggplot2取决于scales,而scales取决于Rcpp与C ++的接口。确保安装了Rcpp并保持最新。

上面的评论指出您的R版本已过时。如果可能的话,我会更新R.这通常可以解决其中的一些问题。您还要从源代码安装 - 您必须这样做吗?尝试回答“没有”#39;当提示从源代码和二进制文件安装软件包时。