19.6 Installing packages

All the fun functions are in packages

R is considered an Open Source software program. That means many (thousands) of people contribute to the software. They do this by writing commands (called functions) to make a particular analysis easier, or to make a graphic prettier.

When you download R, you get access to a lot of functions that we will use. However these other user-written packages add so much good stuff that it really is the backbone of the customizability and functionality that makes R so powerful of a language.

For example we will be creating graphics using functions like boxplot() and hist() that exist in base R. But you will quickly move on to creating graphics using functions contained in the ggplot2 package. We will be managing data using functions in dplyr and reading in Excel files using readxl. Installing packages will become your favorite past-time.

✏️ Start by typing the following in the console to install the ggplot2 package.

install.packages("ggplot2")

When the download and install is complete, you should see a message similar to:

The downloaded binary packages are in
    C:\Users\Robin\AppData\Local\Temp\Rtmpi8NAym\downloaded_packages

⚠️ R is case sensitive and spelling matters. If you get an error message like the following:

Warning in install.packages :
  package ‘ggplot’ is not available (for R version 3.5.1)

The correct package name is ggplot2, not ggplot.

Alternative Method of installing Packages: Use the Package tab in the lower right pane in R Studio.

Keep an eye on the messages that fly by in the console. You are looking for key words such as “error code” or “unable to remove…” to indicate installation problems.

When you see a chevron > in the console you know R is done installing and waiting for you.

19.6.1 Common packages used in this notebook

⚠️ Check with your instructor about which packages to install. You typically do NOT need all of these.

Data Import and Management

  • here
  • tidyverse (an opinionated collection of packages that work well together
  • tidyr
  • palmerpenguins example data

Communication / pretty reporting

  • rmarkdown literate data analysis and creating reports, presentations, websites.
  • pander
  • kableExtra
  • knitr
  • gtsummary

Data Visualization

  • ggplot2 (also contained in tidyverse)
  • ggpubr
  • corrplot visualizing correlation matricies
  • sjPlot
  • gridExtra
  • waffle
  • dotwhisker

Analysis

  • rstanarm or lme4 multi-level modeling
  • mice multiple imputation with chained equations
  • VIM visualizing missing data patterns,
  • caret
  • ROCR
  • factoextra
  • performance
  • broom
  • survey
  • marginaleffects