Joshua L. Britt
ISLR <- read.csv("C:/Users/jbritt11/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)
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
p2
p3
Now Let's put the three plots together using the grid.arrange function. HAVE TO LOAD THE gridExtra package for this function!!!!
library(gridExtra)
grid.arrange(p1, p2, p3, nrow = 1)