Understanding how to use libraries to extend R's functionality
R libraries (also called packages) are collections of R functions, data, and compiled code in a well-defined format. You can install libraries from CRAN (Comprehensive R Archive Network) using the install.packages() function.
install.packages("ggplot2")After installing a library, you need to load it into your R session using the library() function. Once loaded, you can use the functions and datasets provided by the library.
library(ggplot2)
R libraries extend the functionality of R by providing additional functions for data manipulation, visualization, statistical analysis, and more. For example, the ggplot2 library is widely used for creating elegant and informative graphics.
# Example using ggplot2
library(ggplot2)
ggplot(data = mpg, aes(x = displ, y = hwy)) +
geom_point() +
labs(title = "Fuel Efficiency vs. Engine Displacement",
x = "Engine Displacement (L)",
y = "Highway MPG")You can search for R libraries on CRAN or other repositories using the find.package() function or online resources like RDocumentation or CRAN Task Views.
find.package("ggplot2")Now that you've learned about using libraries in R, it's time to practice. Try the following exercises to test your understanding:
tidyverse library and load it into your R session.dplyr library on CRAN and find its latest version.help() function to get documentation for the read_csv() function from the readr library.