Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using ggplot function in R error : could not find function ggplot

Tags:

r

ggplot2

I have installed ggplot and ggplot2 and their dependencies, but I cannot use the function ggplot; whenever I try to use it I get

Error in ggplot ... could not find function "ggplot"

like image 339
optform Avatar asked Aug 10 '11 20:08

optform


People also ask

Why can't I load ggplot2?

It's saying when you try to load ggplot2, it can't because this dependency isn't installed yet. Some options: Just install the full tidyverse: http://tidyverse.tidyverse.org/#installation. This includes Rcpp.

Why can't R find my function?

This error usually occurs when a package has not been loaded into R via library . R does not know where to find the specified function. It's a good habit to use the library functions on all of the packages you will be using in the top R chunk in your R Markdown file, which is usually given the chunk name setup .

Why is Qplot not working?

You'll notice that the qplot() function cannot be found. That's because while ggplot2 is installed (i.e., present in the library), it is not loaded (i.e., off the shelf). If you want to use a function from the ggplot2 package, you need to load the package using the library() function.

How do I import Ggplot into R?

The ggplot2 package can be easily installed using the R function install. packages() . The above code will automatically download the ggplot2 package, from the CRAN (Comprehensive R Archive Network) repository, and install it.


1 Answers

Try:

library(ggplot2) 

Even after installing a package, you have to load a package each time you load R.

This question is answered comprehensively in the r-faq:

Error: could not find function ... in R

like image 185
Ari B. Friedman Avatar answered Sep 29 '22 05:09

Ari B. Friedman