Created
October 28, 2010 17:08
-
-
Save prasoonsharma/651807 to your computer and use it in GitHub Desktop.
R code for bar plot of Tendulkar and Ponting's batting performance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DATA | |
tendulkar <- structure(list(A = c(1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010), B = c(215, 373, 78, 419, 640, 700, 58, 623, 1000, 647, 1088, 575, 1003, 1392, 153, 915, 444, 267, 776, 1063, 541, 1003), C = c(35.83, 37.3, 19.5, 38.09, 71.11, 63.64, 14.5, 41.53, 58.82, 71.89, 57.26, 57.5, 55.72, 53.54, 17, 61, 44.4, 22.25, 48.5, 42.52, 60.11, 77.15)), .Names = c("Year", "Total.Runs.In.Year", "Runs.Per.Match.In.Year"), class = "data.frame", row.names = c(NA, -22L)) | |
ponting <- structure(list(A = c(1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010), B = c(NA, NA, NA, NA, NA, NA, 167, 163, 497, 382, 883, 318, 772, 1064, 1503, 697, 1444, 1333, 192, 1182, 853, 551), C = c(NA, NA, NA, NA, NA, NA, 83.5, 20.38, 45.18, 27.29, 51.94, 45.43, 32.17, 66.5, 83.5, 36.68, 55.54, 74.06, 32, 47.28, 37.09, 42.38)), .Names = c("Year", "Total.Runs.In.Year", "Runs.Per.Match.In.Year"), class = "data.frame", row.names = c(NA, -22L)) | |
tendulkar.vector <- structure(tendulkar[,"Total.Runs.In.Year"],.Names=tendulkar[,"Year"]) | |
ponting.vector <- structure(ponting[,"Total.Runs.In.Year"],.Names=ponting[,"Year"]) | |
# PLOT | |
par(mar=c(4,4,4,4), mfrow=c(2,1)) | |
# First bar plot | |
barplot(tendulkar.vector, main="Tendulkar's One Day Cricket Batting Performance", col="blue", ylab="Total Runs Scored In Year", xlab="Years") | |
segments(0, 1000, 2009, 1000, lty=2, lwd=2, col="black") | |
text(1, 1000 + 100, "1000 runs", cex=0.8, col="black", font=2) | |
# Add line plot | |
par(new=T) | |
plot(tendulkar$Year,tendulkar$Runs.Per.Match.In.Year, type="n",ylim=c(0,100), ylab="", xlab="", axes=F) | |
lines(tendulkar$Year,tendulkar$Runs.Per.Match.In.Year,col="gray", lwd="8") | |
axis(4, at=c(0,25,50,75,100),labels=c("0", "25", "50","75","100"), col.axis="black", las=2, cex=0.5, col="gray", col.axis="gray") | |
mtext("Runs/Match In Year", side=4, at=50, line=2.5, col="gray") | |
# Second bar plot | |
barplot(ponting.vector, main="Ponting's One Day Cricket Batting Performance", col="orange", ylab="Total Runs Scored In Year", xlab="Years") | |
segments(0, 1000, 2009, 1000, lty=2, lwd=2, col="black") | |
text(1, 1000 + 100, "1000 runs", cex=0.8, col="black", font=2) | |
# Add line plot | |
par(new=T) | |
plot(ponting$Year,ponting$Runs.Per.Match.In.Year, type="n",ylim=c(0,100), ylab="", xlab="", axes=F) | |
lines(ponting$Year,ponting$Runs.Per.Match.In.Year,col="gray", lwd="8") | |
axis(4, at=c(0,25,50,75,100),labels=c("0", "25", "50","75","100"), col.axis="black", las=2, cex=0.5, col="gray", col.axis="gray") | |
mtext("Runs/Match In Year", side=4, at=50, line=2.5, col="gray") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment