Skip to main content
Statistics LibreTexts

3.9: Using R Libraries

  • Page ID
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Many of the useful features in R are not contained in the primary R package, but instead come from libraries that have been developed by various members of the R community. For example, the ggplot2 package provides a number of features for visualizing data, as we will see in a later chapter. Before we can use a package, we need to install it on our system, using the install.packages() function:

    > install.packages("ggplot2")
    trying URL '
    Content type 'application/x-gzip' length 3961383 bytes (3.8 MB)
    downloaded 3.8 MB
    The downloaded binary packages are in

    This will automatically download the package from the Comprehensive R Archive Network (CRAN) and install it on your system. Once it’s installed, you can then load the library using the library() function:

    > library(ggplot2)

    After loading the function, you can now access all of its features. If you want to learn more about its features, you can find them using the help function:

    > help(ggplot2)

    This page titled 3.9: Using R Libraries is shared under a CC BY-NC 2.0 license and was authored, remixed, and/or curated by Russell A. Poldrack via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.