Chapter 1 Installing R, RStudio, and Packages

Installing R and RStudio could not be any easier.

R is the language. RStudio is the Integrated Development Environment (IDE). To be honest, all of the work that I have done thus far with R language has actually been done in RStudio. In short, you need to install R (the language), but you can start working in RStudio (the IDE) for all of the contents of this book.

1.1 Step 1: R Language

Install R, the language. Simply go to the link provided below and install the most recent version for your operational system.

Once on the website, go to CRAN on the top left side of the page, then click on the 0-Cloud link. This will take you to the most current version of R. Click on your operational system and follow the instructions.

1.2 Step 2: RStudio

Install RStudio, the IDE. Go to the link below and choose the RStudio Desktop version, the free one.

Download the file and install it. I have never come across any issues with it; simply follow the instructions and make sure that you create a shortcut for RStudio on your desktop.

That’s it! You are now ready to change the way you handle and manipulate data and effectively write simple lines of code that will save you time in your analysis, and provide yourself and your audience with professional-looking data visualization.

1.3 Step 3: Packages

Once you open RStudio (see next section for a quick tour), simply use the function install.packages() to install the required packages.

In this book, we’ll be mainly using the following packages:

  • ggplot2

  • tidyverse (which contains ggplot2 and more)

  • ggthemes

Other packages may be introduced and when they are, I will show you their names and respective codes for their installation.

1.4 RStudio Quick Tour

If you have never worked with RStudio before, here’s a quick overview of the four main panes. To make it easy to navigate through these panes, I’ve colour-coded them and will explain each in the next sections.

1.4.1 The Source Code Pane

Located at the top left corner of the screen, the source code pane is outlined in green in the picture above. This is where R hosts your script(s). A script is a file that saves your lines of code in it. I highly recommend that you always save your work in scripts. You may have various scripts open at once as RStudio organizes them all neatly at the top of this pane, like tabs on an Excel file.

Note: when you first open RStudio there is no script available unless you open RStudio via a script directly from your directory. To create a new script you can use the shortcut Ctrl+Shift+N. Alternatively, you can go to the File option (menu bar at the top), then click on New File, then on R script. You need to save them with a name (just like any regular file) if you want to keep them.

1.4.2 The Environment Pane

Located at the top right corner, this pane is outlined in orange in the picture above. This is where you see what vectors, data sets, and values you created while running codes in R. The other important tab is the History tab. In this tab, you can see every line of code you have written. Other tabs might be listed on this pane but they are beyond the scope of this book. I’ll let you research them as you see fit.

1.4.3 The R Console Pane

Located at the bottom left corner, this pane is outlined in red in the picture above. This is where you see every single command you execute from the script files. I only use the console directly if I need to run a quick line of code that does not necessarily belong to a specific script, for example, install.packages(), or to search up a function through the Help tab.

1.4.4 The Files, Plots, Packages and Help Pane

Located at the bottom right corner, this pane is outlined in blue in the picture above. This is where you see the list of files from any given directory, the plots you created, your installed packages, and the Help tab.

TIP: To update your current packages, simply go to the Packages tab and click on Update. Select all packages to update all new features recently released by each package.