# Calculate correlation coeficient for the differnt explanatory variables and round to 3 decimal place
cors<-c(round(cor(batting$DOUBLE, batting$R), digits=3), round(cor(batting$TRIPLE, batting$R), digit=3), round(cor(batting$HR, batting$R), digits=3), round(cor(batting$SB, batting$R), digits=3))
# Create plot of Runs ~ double, triples, home runs, and stolent bases so I can compare how each one correlates with number of runs scores
# I also split the data up abased on the american leauge and national leauge so I could see if there was any significant differece between the two
r_dub<-ggplot(batting, aes(x=DOUBLE, y = R, color=lgID)) + geom_point(alpha=.2) + geom_smooth(alpha=.3, size=1) + ggtitle("R~Doubles") + xlab(paste("r value = ", toString(cors[1]))) + ylab ("")
r_trip<-ggplot(batting, aes(x=TRIPLE, y = R, color=lgID, lab="balls")) + geom_point(alpha=.2) + geom_smooth(alpha=.3, size=1) + ggtitle("R~Triples") + xlab(paste("r value = ", toString(cors[2]))) + ylab ("")
r_hr<-ggplot(batting, aes(x=HR, y = R, color=lgID)) + geom_point(alpha=.2) + geom_smooth(alpha=.3, size=1) + ggtitle("R~Home Runs") + xlab(paste("r value = ", toString(cors[3]))) + ylab ("")
r_stolen<-ggplot(batting, aes(x=SB, y=R, color=lgID)) + geom_point(alpha=.2) + geom_smooth(alpha=.3, size=1) + ggtitle("R~Stolen Bases") + xlab(paste("r value = ", toString(cors[4]))) + ylab ("")
# Here I use multiplot to plot the different scatterplots in the same pane
multiplot(r_dub, r_trip, r_hr, r_stolen, cols =2)