Getting Set Up for Mapping in R

Getting Set Up for Mapping in R

Introduction

The purpose of this post is to provide installation instructions for R, RStudio, and the various packages which will be used during the Introduction to Mapping with R hosted by GeoPhilly & MaptimePHL.

The primary steps to get setup are as follows:

  1. Download R.
  2. Download RStudio.
  3. Install required packages.

The rest of the post will elaborate on each of these steps.

Installation of R

To install R I will be using the Berkeley Mirror which contains the R installation packages. Click here, then select your operating system:

image

Windows

If you are using a Windows machine you will select the base option in the next screen:

image

Then you need to download the windows executable installer.

image

Once the download is complete run the executable using the default settings. Additional information on installation and FAQ’s can be found here.

Mac OS X

After selecting the (Mac) OS X option you will need to download a package installer based on the version of OS X you are currently running.

image

Once you have downloaded the appropriate .pkg file, open the file and follow the installation instructions.

Linux

After selecting the Linux option select your flavor of Linux.

image

From this point forward follow the installation instructions provided on the page for the selected distribution.

RStudio

RStudio is a great IDE which allows you to write and run scripts, view visualizations, and explore data all in one place. Click here to download RStudio. Select the installer package for your OS and download it.

image

Run the installer with the default options. For additional references on installation check out the FAQ’s and the RStudio community support forum.

NOTE: You do not need to link R and RStudio, this will happen during the installation if the default settings for installation of R and RStudio are used.

Installing Packages

R comes with a base set of packages, but we will be using a few addditional packages for to aid in creating maps. A package is essentially a set of software tools built to accomplish specific tasks, in this case the packages will aid us in mapping. To install the packages, first open RStudio. You will see a screen similar to the one below.

image

In the lower left you will see the terminal where you can type commands. Try it out by copying and pasting the following:

2 + 2

Then hit enter. The terminal will return the value 4. Now that we know R is up and running, copy and paste the following into the terminal:

map.packages <- c("dplyr", "tidyr",
                  "leaflet", "ggplot2",
                  "lubridate", "readr",
                  "knitr")
install.packages(map.packages)

Then press enter. Depending on your OS, you may be asked “Do you want to install from sources the packages which need compilation? y/n:”. Just respond with ‘y’ then press enter.

Once you are finished with installing the packages, you can quit R/RStudio by either typing quit() in the terminal or by closing the RStudio window.

Now that R, RStudio, and the required packages are installed you are ready to go for the meetup. Look forward to seeing you there.