-1

Possible Duplicate:
Error: could not find function … in R

Question: why do my ggplot2 functions not work?

  • Background: Ubuntu 12.04, Gnome Desktop, R 2.15.1, Mirror: http://cran.stat.ucla.edu/

  • First of all, it says downloaded source packages are in '/tmp/Rtmp2GMNV8/downloaded_packages.' THERE IS NO '/tmp/Rtmp2GMNV8/downloaded_packages.'

  • Second, ggplot2 is installed. Why then "could not find function "qplot""???

I've looked for hours and cannot find any answers online. Does anybody know what is going on?

The readout:

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
Community
  • 1
  • 1
meh
  • 2,591
  • 4
  • 20
  • 33

1 Answers1

11

You need to load the package first. See the link joran gave in comments but:

library(ggplot2)

qplot(caret, price, data=diamonds)
Justin
  • 42,475
  • 9
  • 93
  • 111
  • 6
    I think this deserves a FAQ citation. Oh, there it is. http://cran.r-project.org/doc/FAQ/R-FAQ.html#I-installed-a-package-but-the-functions-are-not-there – IRTFM Jul 04 '12 at 23:50
  • Ahh [expletive deleted]. Newbie mistake. My bad. – meh Jul 05 '12 at 01:28