Chernoff Faces from aplpack

I’ve been playing around with the faces function from the R package aplpack.  I haven’t used it in a while, but there are some new features that I’ve either never noticed before or they are new.  Color has been added to the faces and you can now plot the faces.  There is also the superfluously fantastic option of displaying the faces as Santa Claus.

Here are some of my examples:

Golf: Statistics from several of my friends collected via oobgolf.com.  (I’m SITW on the lower right.) The face is handicap, the mouth is scoring average, the eyes are average putts, the hair is the percentage of fairways hit, nose is greens in regulation (GIR), and ears are the total number of rounds you play. The faces are plotted with fairway percentage on the x-axis and GIR on the y-axis.

Santa_Golf: Same golf data with Santa option.

NFL2010: Final NFL regular season team statistics.  The face represent the offense and the defense is represented by hair. The size of the nose indicates sacks, the ears indicate turnovers (ear width is interceptions; ear height is forced fumbles).  The eyes indicate penalties and, finally, the size of the mouth indicates wins with a smiling face if the team made the playoffs (a really nice touch, if you ask me.)  The face at the bottom right indicates the league leader.

Some observations on the NFL faces:  The two superbowl teams last year (Pittsburgh and Green Bay) are both located at the bottom of the graph and there faces look very, very similar.  San Diego looks similar to to both Green Bay and Pittsburgh (similar face, nose, eyes, and hair), but the big differences are the ears and, of course, the San Diego face is frowning.  Another thing that pops out at me is how similar Houston and New England look to each other.  They have very similar face shape, eyes, and hair.  The big differences are the nose and ears (sacks and turnovers).

 

Cheers.

##NFL CODE

library(aplpack)

 

x<-read.csv(“\StatsInTheWild\NFL2010.csv”,header=TRUE)

x[33,]<-x[32,]

x$abbr<-sort(c(“NE”,”NYJ”,”Mia”,”Buf”,”Pit”,”Bal”,”Cle”,”Cin”,”Ind”,”Jac”,”Hou”,

“Ten”,”KC”,”SD”,”Oak”,”Den”,”Phi”,”NYG”,”Dal”,”Was”,”Chi”,”GB”,”Det”,”Min”,”Atl”

,”NO”,”TB”,”Car”,”Sea”,”StL”,”SF”,”Ari”,”ZZ”))

x$abbr[27:28]<-c(“SF”,”Sea”)

x$abbr[33]<-“League Leader”

x$lab<-paste(x$abbr,x$W,sep=”: “)

x$TOP<-as.numeric(substring(x$TOP.x,1,2))

##Playoff Teams: creating a playoff indicator

rows<-c(2,3,6,12,14,16,19,20,22,24,25,28)

x$playoffs<-rep(0,33)

x$playoffs[rows]<-1

 

##Finding the league leader in all variables

num<-sapply(x,is.numeric)

x[33,num]<-sapply(x[,num],max)

def<-c(6,22:23,26:29)

x[33,def]<-sapply(x[,def],min)

x$lab<-paste(x$abbr,x$W,sep=”: “)

##Defining the names

names(x)[c(2,3)]<-c(“Wins”,”Losses”)

names(x)[c(13,14,15,16)]<-c(“Off PPG”,”Off YPG”,”Off Pass”,”Off Rush”)

names(x)[c(22,23)]<-c(“Penalties”,”Pen Yards”)

names(x)[c(26:29)]<-c(“Def PPG”,”Def YPG”,”Def Pass”,”Def Rush”)

names(x)[c(5:6)]<-c(“Points For”,”Points Against”)

pdf(“/StatsInTheWild/NFL2010.pdf”,width=15,height=10)

##Columns used for plotting

x<- x[order(x[,4]),]

plot.cols<-c(5,6)

##Offense = face, Defense = hair, penalty= eyes, Wins and playoffs = mouth, turnovers = ears

##Columns used for faces: which columns am i going to use for the data

col<-c(15,16,14,2,2,41,22,23,28,29,27,36,36,30,32)

##creating the faces without plotting them.

a<-faces(x[,col],labels=x$lab,face.type=1,plot=FALSE)

##creating text for the legend

g<-paste(a[[2]][,1],a[[2]][,2],sep=”: “)

##building the plot

plot(x[,plot.cols],bty=”n”,xlim=c(200,600),main=”2010 NFL Season”)

text(rep(540,15),seq(475,325,length.out=15),g)

##plotting the faces

plot.faces(a,x[,plot.cols[1]],x[,plot.cols[2]],width=30,height=30)

dev.off()

Advertisements

Posted on August 7, 2011, in Math Pictures, Sports. Bookmark the permalink. 1 Comment.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: