Chapter 1. R Basics
This chapter covers the basics: installing and using packages and loading data.
Most of the recipes in this book require the ggplot2, dplyr, and gcookbook packages to be installed on your computer. (The gcookbook package contains the data sets used in some of the examples, but is not necessary for doing your real work.) If you want to get started quickly, run:
install.packages("tidyverse")install.packages("gcookbook")
Then, in each R session, before running the examples in this book, you can load them with:
library(tidyverse)library(gcookbook)
Running library(tidyverse) will load ggplot2, dplyr, and a number of
other packages. If you want to keep your R session more streamlined and
load only the packages that are strictly needed, you can load the ggplot2
and dplyr packages individually:
library(ggplot2)library(dplyr)library(gcookbook)
Note
If you want a deeper understanding of how ggplot2 works, see Appendix A, which explains the concepts behind ggplot2.
Packages in R are collections of functions and/or data that are bundled up for easy distribution, and installing a package will extend the functionality of R on your computer. If an R user creates a package and thinks that it might be useful for others, that user can distribute it through a package repository. The primary repository for distributing R packages is called CRAN (the Comprehensive R Archive Network), but there are others, such as Bioconductor, which specializes in packages related to genomic ...