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 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 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 data.
If you have spent much time learning R, you may have heard of the tidyverse, which is a collection of R packages that share common ideas of how data should be structured and manipulated. This is in contrast to base R, which is the set of packages that are included when you just download and install R. The tidyverse is a set of add-ons for R, which make it easier to do many operations related to data manipulation and visualization. This book mostly uses the tidyverse, as I believe that it provides a quicker and simpler (but not less powerful!) way to work with data.
If you haven’t used the tidyverse before, there is one recipe in particular that you should read that will help you understand a foreign-looking bit of syntax: %>%
, also known as the pipe operator. This is Recipe 1.7 in this chapter.