# setup library and dataset...

nfl <- read.csv("nfl2012_stats.csv", header=TRUE, sep=",", as.is=TRUE)

install.packages(c("plyr", "reshape2", "stringr", "ggplot2"))

library(ggplot2)

# execute basic scatter plot, x-y axes...

sp <- ggplot(nfl, aes(PTS_DEF, PTS_OFF, color=POWER_FACTOR))

sp <- sp + geom_point(shape=20, size=.6*nfl$WINS) + scale_x_reverse()

 +   scale_colour_gradient(low = "red")

# generate title, labels, and breakeven slope line...

sp <- sp + xlab("Defensive Prowess >>") + ylab("Offensive Prowess >>")

sp <- sp + theme(legend.position="none") + ggtitle("NFL 2012 Regular Season")

sp <- sp + geom_abline(intercept = 0, slope = -1, colour = "green", size = .75)

# annotate with shaded regions for top 20%-tiles...

sp <- sp + annotate("rect", xmin=14,xmax=19.75,ymin=20,ymax=33,alpha=.1,colour="brown")

sp <- sp + annotate("rect", xmin=17,xmax=29,ymin=26.6,ymax=35.6,alpha=.2,colour="orange")

sp <- sp + annotate("text", y = 35, x = 26.8, label = "OFF. TOP 20%", size=3)

sp <- sp + annotate("text", y = 20.7, x = 16.2, label = "DEF. TOP 20%", size=3)

# annotate each point with team name...

sp <- sp + annotate("text", y=34.5, x=20.6, label = "NE", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=29.8, x=18.8, label = "DEN", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=28.7, x=27.9, label = "NO", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=24.7, x=14.5, label = "SEA", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=24.6, x=16.5, label = "SF", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=23, x=16.8, label = "CHI", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=26.3, x=17.9, label = "ATL", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=13, x=26, label = "KC", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=16, x=27.3, label = "JAC", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=20.8, x=28.8, label = "TEN", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=17.5, x=27.2, label = "PHI", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=18.3, x=27.1, label = "OAK", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=15.8, x=21.9, label = "AZ", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=17.1, x=22.8, label = "NYJ", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=22.2, x=21.4, label = "SD", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=21.6, x=24, label = "IND", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=24, x=20.5, label = "CIN", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=21.4, x=19.1, label = "PIT", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=27.3, x=23.5, label = "WAS", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=27.7, x=20.5, label = "GB", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=27.2, x=22.1, label = "NYG", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=26.0, x=21.5, label = "HOU", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=17.9, x=19.3, label = "MIA", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=23.5, x=22.3, label = "MIN", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=24.8, x=22.1, label = "BAL", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=21.8, x=22.7, label = "CAR", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=22.7, x=23.9, label = "TB", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=18.6, x=21.2, label = "STL", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=23.4, x=25.5, label = "DAL", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=21.5, x=26.6, label = "BUF", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=18.8, x=23.5, label = "CLE", size = 2, color = "dark blue")

sp <- sp + annotate("text", y=23.2, x=26.5, label = "DET", size = 2, color = "dark blue")

# display completed scatter plot...

sp