Barry Grant < http://thegrantlab.org/bggn213/ >
2019-10-15 (19:18:29 on Tue, Oct 15)
One of the biggest attractions of the R programming language is the ability to have complete programmatic control over the plotting of complex graphs and figures. In this session we will introduce base R functions for generating simple plots and explore the generation of more complex multi-layered figures with custom positioning, layout, fonts and colors.
Sections 1 to 3 are exercises designed to test and expand your familiarity with R base plotting. Section 4 feature a detailed guide to plotting with base R and will be useful for answering questions throughout your subsequent projects. 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 an R newcomer 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 with a new RStudio Project specifically for todays class. For now think of this as a folder on your computer where we will store all our work (documented in a new R script), input (the data we will analyze) and output (the graphs, figures and reports we will generate).
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 course organized. For example, for me this is a directory on my Desktop with the course 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 course. N.B. Staying organized like this will be very helpful later in the course when we come to make an on-line portfolio of your work.
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 folder.
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.