library(RCurl)
## Loading required package: bitops
library(tidyr)
## 
## Attaching package: 'tidyr'
## The following object is masked from 'package:RCurl':
## 
##     complete
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(useful)
## Loading required package: ggplot2
URL <- getURL("https://raw.githubusercontent.com/DanielBrooks39/IS607/master/Project%202/NBA%20wins.csv")
WinData <- read.csv(text = URL, header = TRUE)
tbl_df(WinData)
## Source: local data frame [26 x 33]
## 
##    Rk.U.0098..  Season     Lg   ATL   BOS   BRK   CHI   CHO   CLE   DAL
##          (int)  (fctr) (fctr) (int) (int) (int) (int) (int) (int) (int)
## 1            2 2014-15    NBA    60    40    38    50    33    53    50
## 2            3 2013-14    NBA    38    25    44    48    43    33    49
## 3            4 2012-13    NBA    44    41    49    45    21    24    41
## 4            5 2011-12    NBA    40    39    22    50     7    21    36
## 5            6 2010-11    NBA    44    56    24    62    34    19    57
## 6            7 2009-10    NBA    53    50    12    41    44    61    55
## 7            8 2008-09    NBA    47    62    34    41    35    66    50
## 8            9 2007-08    NBA    37    66    34    33    32    45    51
## 9           10 2006-07    NBA    30    24    41    49    33    50    67
## 10          11 2005-06    NBA    26    33    49    41    26    50    60
## ..         ...     ...    ...   ...   ...   ...   ...   ...   ...   ...
## Variables not shown: DEN (int), DET (int), GSW (int), HOU (int), IND
##   (int), LAC (int), LAL (int), MEM (int), MIA (int), MIL (int), MIN (int),
##   NOP (int), NYK (int), OKC (int), ORL (int), PHI (int), PHO (int), POR
##   (int), SAC (int), SAS (int), TOR (int), UTA (int), WAS (int)
TidyData <- gather(WinData,"Team", "Wins",4:33)
names(TidyData) <- c("Num", "Season", "League","Team", "Wins")

TidyData <- TidyData %>% separate(Season, c("Start", "End"), sep = "-")
TidyData <- select(TidyData, Start, Team, Wins)

Box Plot broken apart by each team

ggplot(TidyData, aes(x=Team, y=Wins, fill = Team)) + geom_boxplot() + theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust=.5, face="bold", size = 10)) + ggtitle("Wins By Each Team (1989-2014)") + theme(plot.title=element_text(face="bold", size = 20)) + theme(axis.title.x = element_text(face="bold", size = 15), axis.title.y = element_text(face="bold", size= 15)) + scale_y_continuous(breaks=c(10, 20, 30, 40, 50, 60, 70))
## Warning: Removed 27 rows containing non-finite values (stat_boxplot).

* This is a Box Plot that will show you the break down of each team (1989-2014). It will show you the average number fo wins over the time span, the quartiles over the time span, and the most and least number of wins over the time span.We can see by the graph that SAS (the Spurs) have the most averages wins over all of the other teams over the time span. They have a very close together box plot, meaning their wins do not vary from year to year. It shows that they are a pretty consist team.


Bar Graph of most wins in a season (1989-2014) by Team

ggplot(TidyData,aes(x=Team, y=Wins, fill = Team)) + geom_bar(stat="identity", position="dodge") + theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = .5, face="bold", size=10), axis.title=element_text(face="bold", size = 15)) + ggtitle("Max Wins By Team") + theme(plot.title = element_text(face="bold", size=20)) + theme(legend.title=element_text(face="bold", size=15, color="white"), legend.background=element_rect(fill="black"), legend.text=element_text(face="bold", color="white", size=10)) + scale_y_continuous(breaks=c(10, 20, 30, 40, 50, 60, 70))

* This is a bar graph that show the highest number of wins a team. WE can see that the Chicago Bulls(CHI) have the most wins over the time span. The currently hold the recod for the best record in NBA history with 72, we can see that there is really no team that has come close to the number. (Golden State is on track for beating that record this basketball season


Bar Graph of most loses in a season (1989-2014) by Team

TidyData <- TidyData %>% mutate(Loses = 82-Wins)
ggplot(TidyData,aes(x=Team, y=Loses, fill = Team)) + geom_bar(stat="identity", position="dodge") + theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = .5, face="bold", size=10), axis.title=element_text(face="bold", size = 15)) + ggtitle("Max Loses By Team") + theme(plot.title = element_text(face="bold", size=20)) + theme(legend.title=element_text(face="bold", size=15, color="white"), legend.background=element_rect(fill="black"), legend.text=element_text(face="bold", color="white", size=10)) + scale_y_continuous(breaks=c(10, 20, 30, 40, 50, 60, 70))

* This is a bar graph that shows the most loses by team in a given season over the time span. We can see that Charlotte(Bobcats/Hornets) has the most loses out of any team. The look to have lost around 75 games! That means the only won 7 games all season. Memphis and LA Clippers are pretty close as well.