R ggplot2函数不起作用

时间:2012-07-04 22:55:04

标签: r package ggplot2

  

可能重复:
  Error: could not find function … in R

问题:为什么我的ggplot2功能不起作用?

  • 背景:Ubuntu 12.04,Gnome Desktop,R 2.15.1,镜像:http://cran.stat.ucla.edu/

  • 首先,它说下载的源包位于'/ tmp / Rtmp2GMNV8 / downloaded_pa​​ckages'。没有'/ tmp / Rtmp2GMNV8 / downloaded_pa​​ckages。'

  • 其次,安装了ggplot2。为什么然后“找不到功能”qplot“”???

我已经找了好几个小时,在网上找不到任何答案。有人知道发生了什么吗?

读数:

emilio@dog:~/R$ sudo R

R version 2.15.1 (2012-06-22) -- "Roasted Marshmallows"

# I've taken the liberty of omitting a few lines

> install.packages("ggplot2", dependencies=TRUE)
Installing package(s) into ‘/usr/local/lib/R/site-library’
[...]
* DONE (SparseM)
* DONE (sp)
* DONE (mvtnorm)
* DONE (evaluate)
* DONE (Hmisc)
* DONE (maps)
* DONE (hexbin)
* DONE (gpclib)

* 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
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded

* DONE (ggplot2)
* DONE (quantreg)
* DONE (mapproj)
* DONE (maptools)
* DONE (multcomp)
* DONE (testthat)

The downloaded source packages are in
    ‘/tmp/Rtmp2GMNV8/downloaded_packages’
> help(qplot)
No documentation for ‘qplot’ in specified packages and libraries:
you could try ‘??qplot’
> help(ggplot)
No documentation for ‘ggplot’ in specified packages and libraries:
you could try ‘??ggplot’
> data(diamonds, package="ggplot2")
> head(diamonds)
  carat       cut color clarity depth table price    x    y    z
1  0.23     Ideal     E     SI2  61.5    55   326 3.95 3.98 2.43
2  0.21   Premium     E     SI1  59.8    61   326 3.89 3.84 2.31
3  0.23      Good     E     VS1  56.9    65   327 4.05 4.07 2.31
4  0.29   Premium     I     VS2  62.4    58   334 4.20 4.23 2.63
5  0.31      Good     J     SI2  63.3    58   335 4.34 4.35 2.75
6  0.24 Very Good     J    VVS2  62.8    57   336 3.94 3.96 2.48
> qplot(carat, price, data = diamonds)
Error: could not find function "qplot"

emilio@dog:~$ cd /tmp/Rtmp2GMNV8/downloaded_packages
bash: cd: /tmp/Rtmp2GMNV8/downloaded_packages: No such file or directory

1 个答案:

答案 0 :(得分:12)

您需要先加载包。请参阅评论中的joran链接,但是:

library(ggplot2)

qplot(caret, price, data=diamonds)