# setup library and dataset...

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

library(ggplot2)

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

sp2<-ggplot(nfl, aes(PROJ_WINS, WINS, color=POINTSF-POINTSA))

sp2<-sp2+geom_point(shape=20, size=12*nfl$CLOSE_PCT)+scale_colour_gradient(low="black")

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

sp2<-sp2+xlab("Pythagorean Wins")+ylab("Actual Wins")

sp2<-sp2+ggtitle("NFL 2012 PYTHAGOREAN DISPARITY")

sp2<-sp2+geom_abline(intercept=0, slope=1, colour="red", size=.90)

# generate thinner slope lines for +1,-1 and +2,-2 Pythagorean disparity...

sp2<-sp2+geom_abline(intercept=1, slope=1, colour="orange", size=.40)

sp2<-sp2+geom_abline(intercept=2, slope=1, colour="brown", size=.40)

sp2<-sp2+geom_abline(intercept=-1, slope=1, colour="orange", size=.40)

sp2<-sp2+geom_abline(intercept=-2, slope=1, colour="brown", size=.40)

# annotate each point with team name...

sp2<-sp2+annotate("text",y=2.1,x=3.7,label="JAC",size=2,color="brown")

sp2<-sp2+annotate("text",y=4.1,x=6.85,label="DET",size=2,color="brown")

sp2<-sp2+annotate("text",y=8.9,x=10.4,label="NYG",size=2,color="brown")

sp2<-sp2+annotate("text",y=10.9,x=12.0,label="SEA",size=2,color="brown")

sp2<-sp2+annotate("text",y=5.1,x=6.5,label="CLE",size=2,color="brown")

sp2<-sp2+annotate("text",y=6.1,x=5.2,label="TEN",size=2,color="brown")

sp2<-sp2+annotate("text",y=10.1,x=6.7,label="IND",size=2,color="brown")

sp2<-sp2+annotate("text",y=10.1,x=8.4,label="MIN",size=2,color="brown")

sp2<-sp2+annotate("text",y=6.9,x=8.45,label="NO",size=2,color="brown")

sp2<-sp2+annotate("text",y=12.9,x=10.7,label="ATL",size=2,color="brown")

sp2<-sp2+annotate("text",y=11.9,x=9.65,label="HOU",size=2,color="brown")

# display completed scatter plot...

sp2