BIMM-143 Lecture 5:
Barry Grant < http://thegrantlab.org/bimm143/ >
2018-10-12 (09:03:06 PDT on Fri, Oct 12)
One of the biggest attractions to the R programming language is that built into the language is the functionality required to have complete programmatic control over the plotting of complex figures and graphs. Whilst the use of these functions to generate simple plots is very easy, the generation of more complex multi-layered plots with precise positioning, layout, fonts and colors can be more challenging for new users.
Sections 1 to 4 are exercises designed to test and expand your familiarity with R base plotting. Section 5 feature a rather detailed guide to plotting with base R and will be useful for answering the questions in the first four sections. My objective with the last section is to provide you with everything you would need to create plots for almost any kind of data you may encounter in the future.
Side-note: While I have attempted to cover all of the major graph types you are likely to use as a newcomer to base R these are obviously not the only way to do plotting in R. There are many other R graphing packages and libraries, which can be imported and each of these has advantages and disadvantages. The most common, and ridiculously popular, external library is ggplot2, – we will introduce this add on package from CRAN next day.
1A. We will begin by getting organized. This entails creating a new RStudio Project, creating a new R script, and downloading the input data we will use For this hands-on session.
File > New Project > New Directory > New Project
make sure you are working in the directory (a.k.a. folder!) where you want to keep all your work for this class organized. For example, for me this is a directory on my Desktop with the class name (see animated figure below). We will create our project as a sub-directory called class05
in this location.The key step here is to name your project after this class session (i.e. “class05”) and make sure it is a sub-directory of where ever you are organizing all your work for this class (see image above for an example).
1B. Your next task is to download the ZIP file containing all the input data for this lab to your computer and move it to your RStudio project.
bimm143_05_rstats
. Check your Downloads directory/folder. However, some computers may require you to double click on the ZIP file to begin the unzipping process.bimm143_05_rstats
folder into your R project directory. You can use your Finder window (on Mac) or File Explorer (on Windows) to do this.