ISLR <- read.csv("C:/Users/Joshua/Dropbox/R/ISLR.csv")
head(ISLR[,1:4])
##      TV Radio Newspaper Sales
## 1 230.1  37.8      69.2  22.1
## 2  44.5  39.3      45.1  10.4
## 3  17.2  45.9      69.3   9.3
## 4 151.5  41.3      58.5  18.5
## 5 180.8  10.8      58.4  12.9
## 6   8.7  48.9      75.0   7.2
attach(ISLR)

Let’s compare the base plot to the ggplot!! Here is the base plot of Sales vs TV

plot(Sales,TV)

plot of chunk Base Plot

Now make a plot using ggplot #!!!!!!!!!!!!! KEY TO LOAD PACKAGE INSIDE MARKDOWN

library(ggplot2)

create the base ggplot #!!!!!!!!!!!!! KEY TO LOAD PACKAGE INSIDE MARKDOWN

g1=ggplot(aes(TV,Sales),data=ISLR)
g2=ggplot(aes(Radio,Sales),data=ISLR)
g3=ggplot(aes(Newspaper,Sales),data=ISLR)

Now that the base graphic is created in g we can start adding stuff on!!

p1=g1+geom_point()+geom_smooth(method="lm")
p2=g2+geom_point()+geom_smooth(method="lm")
p3=g3+geom_point()+geom_smooth(method="lm")
p1

plot of chunk Add Stuff on

p2

plot of chunk Add Stuff on

p3

plot of chunk Add Stuff on

Now Let’s put the three plots togehter using the grid.arrange function. HAVE TO LOAD THE gridExtra package for this function!!!!

library(gridExtra)

grid.arrange(p1, p2, p3, nrow=1)

plot of chunk combine p1 p2 p3