Your verification ID is: guDlT7MCuIOFFHSbB3jPFN5QLaQ Big Computing: An Example of Doing a Matrix Plot in Base R

Monday, October 6, 2014

An Example of Doing a Matrix Plot in Base R

The matplot function is Base R is a great way to visualize matrix data to look for relationships. It is a very flexible format that allows a use to plot data as points, lines or a combination of both. Matplot is often forgotten about but useful plot.
For the first example I have upload the weekly individual scores of the playes in my fantasy football league.
player1<-c(140,131,80,73,74,101,82,67,81,77,112,79)
player2<-c(110,111,68,118,122,132,116,99,80,97,97,101)
player3<-c(91,135,129,153,131,69,115,129,43,71,74,68)
player4<-c(137,103,119,128,83,98,99,86,127,113,102,117)
player5<-c(124,85,117,100,77,98,105,95,177,96,124,123)
player6<-c(138,135,82,122,69,121,65,117,96,90,113,88)
player7<-c(109,107,70,125,69,81,102,78,190,115,108,99)
player8<-c(161,95,120,173,122,145,138,158,143,127,100,113)
scores<-cbind(player1,player2,player3,player4,player5,player6,player7,player8)
rownames(scores)<-c("week1","week2","week3","week4","week5","week6","week7","week8","week9","week10","week11","week12")
Now lets plot it in the most basic way
matplot(scores)
plot of chunk unnamed-chunk-2
It is ok, but not really readable. Inorder to help with that lets change this to from the default numbered point to a dot line and add a legend to the x-axis and a Main title.
matplot(scores,type="o",pch=20,main="Data Scientist's Fantasy Football",xlab="Week")
plot of chunk unnamed-chunk-3 Now it is much more readable how about we add a mean indicating the mean scores to the entire league and add it to the plot.
matplot(scores,type="o",pch=20,main="Data Scientist's Fantasy Football",xlab="Week")
abline(h=mean(scores),lwd=2)
plot of chunk unnamed-chunk-4
So that is matplot pretty easy and pretty useful.

1 comment: