General Navigation in R

So you’ve finally managed to install the pesky environment but have no idea what you are looking at when you open the program. This tutorial is for you. (Again, here is a version with screenshot pictures).

When you open R, it might look different than the screenshots in the picture version of the tutorial. This depends on what type of computer you are using and how you installed R (look at step 8 of the installation post).


When you first open R, there should be a window with this information in it. The version of your copy of R can be found at the beginning (starred). Every time you open R, this window is called the workspace. A workspace can be likened to a box. You can put multiple things in the box and rearrange and analyze the objects in the box. Depending on how you installed R, you can have multiple workspaces/boxes open to put in and remove things. When you open R, you can have a new box or old box (saved workspace) opened depending on how you closed R. More information on that later.

Now we are going to try entering in the command “help.start()” which will open a help guide in Chrome, Firefox, Safari etc. In the previous screenshot, there is a box around the greater-than sign (“>”). This is where you write directions to R. Try typing “help.start()” exactly (without the quotation marks) and press the Enter/Return key.


*From now on, commands will be written like so


When the command is finished running (R has heard and followed your instructions), another greater-than sign should appear. You would then be able to write another command and run it. (When you run scripts that require lots of time and computation, this sign will become a symbol of relief, happiness and many other positive emotions).  Depending on the command, R will spit out some output about what it is doing or results from the instructions before the greater-than sign appears. (Marked by an arrow in the following picture).

Here is that happy symbol of a successfully run code and then a help screen pops up. If you click on “An Introduction to R” there are a myriad of tutorials already written for R that were installed on your computer when you installed R.


Alternatively, you could get a PDF version of the guide by clicking on the top menu Help>Manuals (in PDF)>An Introduction to R. Although it is easy to look for answers using the all powerful tool Google, this PDF is a solid, 101-page introduction to R. A downloadable version from the internet can also be found here.

Although R is good at following instructions, it is pickier than a toddler choosing what to eat when it comes to written commands. You have to write commands exactly for them to be performed. So you  will not misspell, not change uppercased and lowercased letters and definitely not change a location of a period or underscore. If you do, R will whine and spit out an error message in response to your command.

Picky R doesn't like anything new

Picky R doesn’t like anything new

Let’s try some basic arithmetic. Remember to press enter between each line.

remember PEMDAS!

remember PEMDAS!

You can also create objects (now let’s remember algebRa) by assigning numbers or even other objects to the new object.



If you type the name of these objects, you can see what each object contains.



To see all the objects you have in your workspace (or box, to continue the earlier metaphor):



You can reassign new contents to an object.



An object can contain more than just one number. Here are some different versions of sequences.

y<-seq(1,21, by=2)
z<-seq(0,100, length=9)


If you want to repeat a function you wrote earlier, press on the up or down buttons on your keyboard.

You can also erase all the objects in your workspace.



To exit R, you can either close out of it or type


How courteous of R

Either way, R will ask if you would like to save your workspace. If you choose to save, R will remember objects in the workspace even if you turn off your computer.

Here is a link to an excellent and shorter introduction to R (compared to the earlier one we opened up through R) if you would like to get more comfortable navigating in R.

Scatterplot Matrices

Scatterplot matrices are a great way to roughly determine if you have a linear correlation between multiple variables. This is particularly helpful in pinpointing specific variables that might have similar correlations to your genomic or proteomic data. If you already have data with multiple variables, load it up as described here.

If not, no worries because R comes with some various presaved datasets for practice (some are more interesting than others. To view these datasets, input the following.


For this tutorial, we will be looking at the datasets trees and ChickWeight.  First, load or open these datasets.


To see the actual data contained by these datasets, just write the title of the dataset.

  • The trees dataset seems to contain three columns of measurements: Girth, Height and Volume.
  • The ChickWeight dataset seems to involve little chicklets getting fed different diets and being weighed at various time points.

To find out more information about the datasets and to confirm our observations, put a question mark before the title of the dataset.


Now, you ready for the scatterplot?


Dataset Trees Scatterplot Matrix

This is an example of a scatterplot matrix. The variables are written in a diagonal line from top left to bottom right. Then each variable is plotted against each other. For example, the middle square in the first column is an individual scatterplot of Girth and Height, with Girth as the X-axis and Height as the Y-axis. This same plot is replicated in the middle of the top row. In essence, the boxes on the upper right hand side of the whole scatterplot are mirror images of the plots on the lower left hand.

In this scatterplot, it is probably safe to say that there is a correlation between Girth and Volume (Go data! Confirming the obvious) because the plot looks like a line. There is probably less of a correlation between Height and Girth in addition to Height and Volume. More statistical analyses would be needed to confirm or deny this.

Now for ChickWeight.


Dataset ChickWeight Scatterplot

This scatterplot matrix is unfortunately not as clean as the last plot because it contains discrete data points for Time, Chick and Diet. However, much can still be extracted from this scatterplot matrix (think about BS exercises you might have done for English or Art) about experimental design and possible outcomes.

  • Scatterplots related to Time are evenly distributed into columns or rows, suggesting that data was actually collected in a regimented fashion. (As in, data was collected at the times it should have been for all the Chick samples).
  • There were about 50 chicks. The first 20 were on diet 1 and then the next three groups of 10 were given diet 2, 3 or 4.
  • Looking at Row 4, Column 1, there is a possibility that chicks on diet 3 gained more weight than chicks on diets 1, 2 or 4.
  • Looking at Row 2, Column 1, it seems that chicks weighed about the same amount at the beginning of the experiment but variation increased as time passed on. In general, there is an increase in weight.

There you have it!

In conclusion,

  • Scatterplot matrices are good for determining rough linear correlations of metadata that contain continuous variables.
  • Scatterplot matrices are not so good for looking at discrete variables.

Soup up your R environment: how to install packages

Today we are going to make additions to our R environment in a common process called installing packages. The transition won’t be as long, drastic nor emotional as an episode of Extreme Makeover: Home Edition, but it does add on more capabilities to your R environment.

Wow...I would like to live in a house like this

Extreme Makeover: Home Edition in Houston as published by Houston’s Real Estate Landscape Swamplot

A package is a bunch of codes combined and distributed through the different R mirrors/servers. Packages usually serve a specific function such as analyzing certain types of data or assisting in multi-server computing. Today, we are going to install ggplot2 and gplots, both of which are commonly used in creating different figures.

I will briefly enumerate the installation steps here which fall roughly into two parts. If you would like screenshots of the process in addition to the instructions, click here.

Method 1 (less typing)

Part 1-Getting the Package onto Your Computer

  1. Open R via  your preferred method (icon on desktop, Start Menu, dock, etc.)
  2. Click “Packages” in the top menu then click “Install package(s)”. 
  3. Choose a mirror that is closest to your geographical location.
  4. Now you get to choose which packages you want to install. If you would like to install multiple packages, click on each one while holding the CTRL key or the cloverleaf-looking key. For now just highlight “ggplot2”.
  5. You will know when the package has been downloaded onto your computer when another greater-than symbol (“>”) appears.

Part 2-Loading the Package into R

  1. Type “library(ggplot2)” and then press the Enter/Return key.
  2. All done.

You will only need to do Part 1 once time on your computer. From now on, you only need to do Part 2 each time you close and restart R.

Method 2 (Quicker)

Use this method once you get more acquainted with the whole copy and paste business. It is much quicker than Method 1.

Part 1-Getting the Package onto Your Computer

  1. Type “install.packages(“gplots”)” and then press the Enter/Return key.
  2. If you have already loaded a package from a server in the R session, then R will automatically install the package. If not, R will automatically prompt you to choose a mirror. Again, choose one close to unless you want to watch a loading bar slowly inch its way to fulfillment.

Part 2-Loading the Package into R

  1. Type “library(gplots)” and then press the Enter/Return key.
  2. All done. R will spit out a lot more output because it needs to install other packages required for gplots.

Again, you will only need to do Part 1 one time on your computer. From now on, you only need to do Part 2 each time you close and restart R.

I thought R was a letter…intro/installation


I will make a confession. This past summer, I didn’t spend my spare time watching relentlessly addicting TV shows nor clubbing in San Francisco. Instead, I checked out figures. No, not the sort of figures you’re probably thinking about. The ones that are included in research papers and have the potential to be beautiful works of art (such as the ones found on the Figured Foundation). And you guessed it, R can be used to generate awesome figures for your last minute put together presentation or end-of-term paper.

Oh yeah. That figure!

Some examples of R graphs found on the R website.

So what the heck is R?

R is a free “environment” that can be used to run statistical analysis and create amazing graphics (a more comprehensive list of R’s superpowers can be found here). It can be installed on Unix, Windows and Apple operating systems. It is considered an “environment” because there tons of add-ons that you can load or write to expand the capabilities of R. In essence, R is a free sports car that you can add rocket power and flying capabilities while still looking cool.

If this is your first time using a form of code, don’t be afraid. Once you get over the hump that R (or any code in general) is relentless about spelling, the process of entering code is no different from choosing the different components of a sundae (do we want strawberries or blueberries as the fruit topping?). And once you get a little more involved, you can start improvising your own crazy creations via the writing of your own functions. This past summer I met a guy that used R to scourge the Travelocity, Priceline, and other airplane ticket finding websites to search for his ideal plane tickets.

So how do I install this?

My apologies ahead of time, but this will be a Windows-centric tutorial. If you would like step by step instructions with screenshots, click here.

  1. Go to the R website and click “Download R” under “Getting Started”
  2. Choose a place to download R. Even though we’re on the limitless and borderless interweb, choosing a location close to you helps speeds things up.
  3. Choose which R package to download based on your operating system in the first box. If you are Unix or Mac user, I apologize buut this is where we now go our separate ways.
  4.  Click on “install R for the first time” then download the file with the biggest font on the top. Then open that puppy up.
  5. Windows might be paranoid and say the publisher could not be verified. Click “run”. Then choose your language.
  6. Click “next” to start the installation, agree to all their legal writings, and selection an installation window.
  7. Select “Core Files” and then either 32-bit or 64-bit files depending on your computer system. (To check, hit Start, right click Computer and select Properties. Look at System Type).
  8. Now you have a choice for Startup Options. I prefer to view the program in multiple separate windows so that I can arrange them on my screen while also have an internet browser or a notepad type program open as well.
    multiple2If you like what you see in the photo above, click “Yes (customized setup)”. If you prefer to have one window with all the components of the program viewed inside that window click “No (accept defaults)” and skip to Step 11.
  9. If you said yes to Step 8, click “SDI (separate windows)”. Next, you can specify plain text or HTML help. I would suggest HTML help because it is easier to view than plain text, which appears in the window.
  10. If you are at an institution that utilizes Internet2.dll, select “Internet 2.” If not or if you are unsure, select “Standard”.
  11. Go ahead and create a program shortcut by clicking “Next“.
  12. Choose if you want to have another icon clutter your desktop and/or Quick Launch toolbar. I suggest leaving the two options under “Registry Entries” selected.
  13. Let it do its thing. Go on Facebook, write a Tweet or run to the bathroom really quick.
  14. Things should be all done! Go update your status or Tweet how excited you are to have installed R.