Chapter 3: Finding your way around

This tutorial is different because it has no explicit challenge at the end of it. It’s optional because what it’s going to help you do is expose you to some commands which are will help you find your way around to simplify the use of R.

Again the same instructions. Type in these commands and you’ll get a feel of what each does.

getwd()
setwd(“dir”)
save.image()
#scroll the previous commands using the arrow keys
history()
history(10)
.Last.value
.last.value
#the above in case you haven’t figured out that R is annoyingly case sensitive
search()
#Installing packagesgoto packages and data (in the mac OSX) and select the package ggplot2 to be installed. Alternatively it ca be installed directly from the command line. The library function loads it into the space.
library(ggplot2)
#R has some inbuilt data sets – let’s explore them
data()
data(trees)
summary(trees)
data(package=”ggplot2″)
# A tiny glimpse of ggplot2
ggplot(data = diamonds, mapping = aes(x = price)) + layer(geom = “bar”, stat = “bin”, mapping = aes(y = ..count..))

#Demo of graphics in R – some fascinating examples of what you can create

demo(graphics)

Once done – Take the above code –copy paste it into an editor and write a comment before the start of each line explaining what it does. Use help() if required.

Concepts introduced: Today we implicitly introduced packages in R – think of packages as pre built modules which are written to help us with certain capabilities. ggplot2 is a powerful graphics package which we will look into depth much later.

Leave a Reply

Your email address will not be published.