ggplot(iris, aes(Species, Petal.Length)) + geom_boxplot()Error in ggplot(iris, aes(Species, Petal.Length)): could not find function "ggplot"
Once you’ve installed a package, you’re nearly ready to use its functions, but there’s still one step left: you must load the package into your active R session.
The following code produces an error because we’re trying to use the ggplot(), aes(), and geom_boxplot() functions provided by the ggplot2 package, without having loaded that package first.
Error in ggplot(iris, aes(Species, Petal.Length)): could not find function "ggplot"
An R package is really just a small piece of software. Like any other software, you only need to install it once (just like you only need to install RStudio once), but you need to load it every time you start a new R session and want to use it (just like you need to open RStudio every time you want to use it).
We load packages with the library() function.
library() can only load one package at a time, so call it once per package if you need more than one.
Running the code below should now produce a simple plot, since we’ve loaded ggplot2 before trying to use the functions it provides.
library() will error with something like “there is no package called…” if the package isn’t installed yet. Installing and loading are two separate steps. You need to install a package (once) before you can ever load it.library(Dplyr) will fail even though library(dplyr) works fine.could not find function "arrange", what’s the most likely fix?You’re ready to move on to Documentation if you can:
install.packages().library().If any of these still feel shaky, revisit the relevant page above, or try the Knowledge Quiz to pinpoint exactly where to focus.