I’ve missed more than 9000 shots in my career. I’ve lost almost 300 games. 26 times, I’ve been trusted to take the game winning shot and missed. I’ve failed over and over and over again in my life. And that is why I succeed.
Michael Jordan
Success is where preparation and opportunity meet.
Bobby Unser
It is not whether you get knocked down. It is whether you get up.
Vince Lombardi
Make sure your worst enemy doesn’t live between your own two ears.
Laird Hamilton
This post should be the last post for “yorkr crashes the IPL party!”. In fact it is final post for the whole ‘yorkr’ series. I have now covered the use of yorkr for ODIs, Twenty20s and IPL T20 formats. I will not be including functionality in yorkr to handle Test cricket from Cricsheet. I would recommend that you use my R package cricketr. Please see my post Introducing cricketr! : An R package to analyze performances of cricketers
In this last post on IPL T20 I look at the top individual batting and bowling performances in the IPL Twenty20s. Also please take a look at my 3 earlier post on yorkr’s handling of IPL Twenty20 matches
This post has also been published at RPubs IPLT20-Part4 and can also be downloaded as a PDF document from IPLT20-Part4.pdf.
You can clone/fork the code for the package yorkr from Github at yorkr-package
The list of Class 4 functions are shown below.The Twenty20 features will be available from yorkr_0.0.4
library(yorkr)
library(gridExtra)
library(rpart.plot)
library(dplyr)
library(ggplot2)
rm(list=ls())
The function below gets the overall IPL team batting details based on the RData file available in IPL T20 matches. This is currently also available in Github at [IPL-T20-matches] (https://github.com/tvganesh/yorkrData/tree/master/IPL/IPL-T20-matches). The batting details of the IPL team in each match is created and a huge data frame is created by rbinding the individual dataframes. This can be saved as a RData file
setwd("C:/software/cricket-package/york-test/yorkrData/IPL/IPL-T20-matches")
csk_details <- getTeamBattingDetails("Chennai Super Kings",dir=".", save=TRUE)
dd_details <- getTeamBattingDetails("Delhi Daredevils",dir=".",save=TRUE)
kkr_details <- getTeamBattingDetails("Kolkata Knight Riders",dir=".",save=TRUE)
mi_details <- getTeamBattingDetails("Mumbai Indians",dir=".",save=TRUE)
rcb_details <- getTeamBattingDetails("Royal Challengers Bangalore",dir=".",save=TRUE)
This function is used to get the individual IPL T20 batting record for a the specified batsman of the team as in the functions below. For analyzing the batting performances I have chosen the top IPL T20 batsmen from the teams. This was based to a large extent on batting scorecard functions from yorkr crashes the IPL party!:Part 3 The top IPL batsmen chosen are the ones below
setwd("C:/software/cricket-package/cricsheet/cleanup/IPL/part4")
raina <- getBatsmanDetails(team="Chennai Super Kings",name="SK Raina",dir=".")
## [1] "./Chennai Super Kings-BattingDetails.RData"
dhoni <- getBatsmanDetails(team="Chennai Super Kings",name="MS Dhoni")
## [1] "./Chennai Super Kings-BattingDetails.RData"
sehwag <- getBatsmanDetails(team="Delhi Daredevils",name="V Sehwag",dir=".")
## [1] "./Delhi Daredevils-BattingDetails.RData"
gambhir <- getBatsmanDetails(team="Kolkata Knight Riders",name="G Gambhir",dir=".")
## [1] "./Kolkata Knight Riders-BattingDetails.RData"
rsharma <- getBatsmanDetails(team="Mumbai Indians",name="RG Sharma",dir=".")
## [1] "./Mumbai Indians-BattingDetails.RData"
kohli <- getBatsmanDetails(team="Royal Challengers Bangalore",name="V Kohli",dir=".")
## [1] "./Royal Challengers Bangalore-BattingDetails.RData"
Sehwag has a superb strike rate. It can be seen that Sehwag averages around 80 runs for around 40 deliveries followed by Rohit Sharma. Raina and Dhoni average around 60 runs
p1 <-batsmanRunsVsDeliveries(raina, "SK Raina")
p2 <-batsmanRunsVsDeliveries(dhoni,"MS Dhoni")
p3 <-batsmanRunsVsDeliveries(sehwag,"V Sehwag")
p4 <-batsmanRunsVsDeliveries(gambhir,"G Gambhir")
p5 <-batsmanRunsVsDeliveries(rsharma,"RG Sharma")
p6 <-batsmanRunsVsDeliveries(kohli,"V Kohli")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)
Dhoni leads in the runs made from sixes in comparison to the others
raina46 <- select(raina,batsman,ballsPlayed,fours,sixes,runs)
p1 <-batsmanFoursSixes(raina46, "SK Raina")
dhoni46 <- select(dhoni,batsman,ballsPlayed,fours,sixes,runs)
p2 <-batsmanFoursSixes(dhoni46,"MS Dhoni")
sehwag46 <- select(sehwag,batsman,ballsPlayed,fours,sixes,runs)
p3 <-batsmanFoursSixes(sehwag46,"V Sehwag")
gambhir46 <- select(gambhir,batsman,ballsPlayed,fours,sixes,runs)
p4 <-batsmanFoursSixes(gambhir46,"G Gambhir")
rsharma46 <- select(rsharma,batsman,ballsPlayed,fours,sixes,runs)
p5 <-batsmanFoursSixes(rsharma46,"RG Sharma")
kohli46 <- select(kohli,batsman,ballsPlayed,fours,sixes,runs)
p6 <-batsmanFoursSixes(kohli46,"V Kohli")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)
The type of dismissal for each batsman is shown below
p1 <-batsmanDismissals(raina, "SK Raina")
p2 <-batsmanDismissals(dhoni,"MS Dhoni")
p3 <-batsmanDismissals(sehwag,"V Sehwag")
p4 <-batsmanDismissals(gambhir,"G Gambhir")
p5 <-batsmanDismissals(rsharma,"RG Sharma")
p6 <-batsmanDismissals(kohli,"V Kohli")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)
Raina, Dhoni and Kohli have an increasing strike rate with more runs scored
p1 <-batsmanRunsVsStrikeRate(raina, "SK Raina")
p2 <-batsmanRunsVsStrikeRate(dhoni,"MS Dhoni")
p3 <-batsmanRunsVsStrikeRate(sehwag,"V Sehwag")
p4 <-batsmanRunsVsStrikeRate(gambhir,"G Gambhir")
p5 <-batsmanRunsVsStrikeRate(rsharma,"RG Sharma")
p6 <-batsmanRunsVsStrikeRate(kohli,"V Kohli")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)
Rohit Sharma seems to maintain an average of almost 30 runs, while Dhoni and Kohli average around 25.
p1 <-batsmanMovingAverage(raina, "SK Raina")
p2 <-batsmanMovingAverage(dhoni,"MS Dhoni")
p3 <-batsmanMovingAverage(sehwag,"V Sehwag")
p4 <-batsmanMovingAverage(gambhir,"G Gambhir")
p5 <-batsmanMovingAverage(rsharma,"RG Sharma")
p6 <-batsmanMovingAverage(kohli,"V Kohli")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)
The cumulative runs average of Raina, Gambhir, Kohli and Rohit Sharma are around 28-30 runs.Dhoni drops to 25
p1 <-batsmanCumulativeAverageRuns(raina, "SK Raina")
p2 <-batsmanCumulativeAverageRuns(dhoni,"MS Dhoni")
p3 <-batsmanCumulativeAverageRuns(sehwag,"V Sehwag")
p4 <-batsmanCumulativeAverageRuns(gambhir,"G Gambhir")
p5 <-batsmanCumulativeAverageRuns(rsharma,"RG Sharma")
p6 <-batsmanCumulativeAverageRuns(kohli,"V Kohli")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)
As seen above Sehwag has a phenomenal cumulative strike rate of around 150, followed by Dhoni around 130, then we Raina and finally Kohli.
p1 <-batsmanCumulativeStrikeRate(raina, "SK Raina")
p2 <-batsmanCumulativeStrikeRate(dhoni,"MS Dhoni")
p3 <-batsmanCumulativeStrikeRate(sehwag,"V Sehwag")
p4 <-batsmanCumulativeStrikeRate(gambhir,"G Gambhir")
p5 <-batsmanCumulativeStrikeRate(rsharma,"RG Sharma")
p6 <-batsmanCumulativeStrikeRate(kohli,"V Kohli")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)
The following charts show the performance of te batsmen against opposing IPL teams
#Kohli's best performances are against New Zealand and Sri Lanka
batsmanRunsAgainstOpposition(raina, "SK Raina")
batsmanRunsAgainstOpposition(dhoni,"MS Dhoni")
batsmanRunsAgainstOpposition(sehwag,"V Sehwag")
batsmanRunsAgainstOpposition(gambhir,"G Gambhir")
batsmanRunsAgainstOpposition(rsharma,"RG Sharma")
batsmanRunsAgainstOpposition(kohli,"V Kohli")
The plots below give the performances of the batsmen at different grounds.
batsmanRunsVenue(raina, "SK Raina")
batsmanRunsVenue(dhoni,"MS Dhoni")
batsmanRunsVenue(sehwag,"V Sehwag")
batsmanRunsVenue(gambhir,"G Gambhir")
batsmanRunsVenue(rsharma,"RG Sharma")
batsmanRunsVenue(kohli,"V Kohli")
The plots below use rpart classification tree to predict the number of deliveries required to score the runs in the leaf node.
par(mfrow=c(1,3))
par(mar=c(4,4,2,2))
batsmanRunsPredict(raina, "SK Raina")
batsmanRunsPredict(dhoni,"MS Dhoni")
batsmanRunsPredict(sehwag,"V Sehwag")
par(mfrow=c(1,3))
par(mar=c(4,4,2,2))
batsmanRunsPredict(gambhir,"G Gambhir")
batsmanRunsPredict(rsharma,"RG Sharma")
batsmanRunsPredict(kohli,"V Kohli")
The function below gets the overall team IPL T20 bowling details based on the RData file available in IPL T20 matches. This is currently also available in Github at [yorkrData] (https://github.com/tvganesh/yorkrData/tree/master/IPL/IPL-T20-matches). The IPL T20 bowling details of the IPL team in each match is created, and a huge data frame is created by rbinding the individual dataframes. This can be saved as a RData file
setwd("C:/software/cricket-package/york-test/yorkrData/IPL/IPL-T20-matches")
kkr_bowling <- getTeamBowlingDetails("Kolkata Knight Riders",dir=".",save=TRUE)
csk_bowling <- getTeamBowlingDetails("Chennai Super Kings",dir=".",save=TRUE)
kxip_bowling <- getTeamBowlingDetails("Kings XI Punjab",dir=".",save=TRUE)
mi_bowling <- getTeamBowlingDetails("Mumbai Indians",dir=".",save=TRUE)
rcb_bowling <- getTeamBowlingDetails("Royal Challengers Bangalore",dir=".",save=TRUE)
rr_bowling <- getTeamBowlingDetails("Rajasthan Royals",dir=".",save=TRUE)
fl <- list.files(".","BowlingDetails.RData")
file.copy(fl, "C:/software/cricket-package/cricsheet/cleanup/IPL/part4")
## [1] FALSE FALSE FALSE FALSE FALSE FALSE
file.remove(fl)
## [1] TRUE TRUE TRUE TRUE TRUE TRUE
This function is used to get the individual bowling record for a specified bowler of the country as in the functions below. For analyzing the bowling performances the following cricketers have been chosen based on the bowling scorecard from my post yorkr crashes the IPL party ! – Part 3
setwd("C:/software/cricket-package/cricsheet/cleanup/IPL/part4")
ashwin <- getBowlerWicketDetails(team="Chennai Super Kings",name="R Ashwin",dir=".")
bravo <- getBowlerWicketDetails(team="Chennai Super Kings",name="DJ Bravo",dir=".")
chawla <- getBowlerWicketDetails(team="Kings XI Punjab",name="PP Chawla",dir=".")
harbhajan <- getBowlerWicketDetails(team="Mumbai Indians",name="Harbhajan Singh",dir=".")
vinay <- getBowlerWicketDetails(team="Royal Challengers Bangalore",name="R Vinay Kumar",dir=".")
sktrivedi <- getBowlerWicketDetails(team="Rajasthan Royals",name="SK Trivedi",dir=".")
Ashwin & Chawla have the best economy rates of in the IPL teams, followed by Harbhajan Singh
p1<-bowlerMeanEconomyRate(ashwin,"R Ashwin")
p2<-bowlerMeanEconomyRate(bravo, "DJ Bravo")
p3<-bowlerMeanEconomyRate(chawla, "PP Chawla")
p4<-bowlerMeanEconomyRate(harbhajan, "Harbhajan Singh")
p5<-bowlerMeanEconomyRate(vinay, "R Vinay")
p6<-bowlerMeanEconomyRate(sktrivedi, "SK Trivedi")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)
p1<-bowlerMeanRunsConceded(ashwin,"R Ashwin")
p2<-bowlerMeanRunsConceded(bravo, "DJ Bravo")
p3<-bowlerMeanRunsConceded(chawla, "PP Chawla")
p4<-bowlerMeanRunsConceded(harbhajan, "Harbhajan Singh")
p5<-bowlerMeanRunsConceded(vinay, "R Vinay")
p6<-bowlerMeanRunsConceded(sktrivedi, "SK Trivedi")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)
Harbhajan’s moving average is the best hovering around 2 wickets
p1<-bowlerMovingAverage(ashwin,"R Ashwin")
p2<-bowlerMovingAverage(bravo, "DJ Bravo")
p3<-bowlerMovingAverage(chawla, "PP Chawla")
p4<-bowlerMovingAverage(harbhajan, "Harbhajan Singh")
p5<-bowlerMovingAverage(vinay, "R Vinay")
p6<-bowlerMovingAverage(sktrivedi, "SK Trivedi")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)
The cumulative average tells a different story. DJ Bravo and R Vinay have a cumulative average of 2 wickets. All others are around 1.5
p1<-bowlerCumulativeAvgWickets(ashwin,"R Ashwin")
p2<-bowlerCumulativeAvgWickets(bravo, "DJ Bravo")
p3<-bowlerCumulativeAvgWickets(chawla, "PP Chawla")
p4<-bowlerCumulativeAvgWickets(harbhajan, "Harbhajan Singh")
p5<-bowlerCumulativeAvgWickets(vinay, "R Vinay")
p6<-bowlerCumulativeAvgWickets(sktrivedi, "SK Trivedi")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)
Ashwin & Harbhajan have the best cumulative economy rate
p1<-bowlerCumulativeAvgEconRate(ashwin,"R Ashwin")
p2<-bowlerCumulativeAvgEconRate(bravo, "DJ Bravo")
p3<-bowlerCumulativeAvgEconRate(chawla, "PP Chawla")
p4<-bowlerCumulativeAvgEconRate(harbhajan, "Harbhajan Singh")
p5<-bowlerCumulativeAvgEconRate(vinay, "R Vinay")
p6<-bowlerCumulativeAvgEconRate(sktrivedi, "SK Trivedi")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)
The plot below gives the average wickets versus number of overs
p1<-bowlerWicketPlot(ashwin,"R Ashwin")
p2<-bowlerWicketPlot(bravo, "DJ Bravo")
p3<-bowlerWicketPlot(chawla, "PP Chawla")
p4<-bowlerWicketPlot(harbhajan, "Harbhajan Singh")
p5<-bowlerWicketPlot(vinay, "R Vinay")
p6<-bowlerWicketPlot(sktrivedi, "SK Trivedi")
grid.arrange(p1,p2,p3,p4,p5,p6, ncol=3)
bowlerWicketsAgainstOpposition(ashwin,"R Ashwin")
bowlerWicketsAgainstOpposition(bravo, "DJ Bravo")
bowlerWicketsAgainstOpposition(chawla, "PP Chawla")
bowlerWicketsAgainstOpposition(harbhajan, "Harbhajan Singh")
bowlerWicketsAgainstOpposition(vinay, "R Vinay")
bowlerWicketsAgainstOpposition(sktrivedi, "SK Trivedi")
bowlerWicketsVenue(ashwin,"R Ashwin")
bowlerWicketsVenue(bravo, "DJ Bravo")
## Warning: Removed 7 rows containing missing values (geom_bar).
bowlerWicketsVenue(chawla, "PP Chawla")
bowlerWicketsVenue(harbhajan, "Harbhajan Singh")
bowlerWicketsVenue(vinay, "R Vinay")
## Warning: Removed 2 rows containing missing values (geom_bar).
bowlerWicketsVenue(sktrivedi, "SK Trivedi")
## Warning: Removed 3 rows containing missing values (geom_bar).
This function creates a dataframe of deliveries and the wickets taken
setwd("C:/software/cricket-package/york-test/yorkrData/IPL/IPL-T20-matches")
ashwin1 <- getDeliveryWickets(team="Chennai Super Kings",dir=".",name="R Ashwin",save=FALSE)
bravo1 <- getDeliveryWickets(team="Chennai Super Kings",dir=".",name="DJ Bravo",save=FALSE)
chawla1 <- getDeliveryWickets(team="Kings XI Punjab",dir=".",name="PP Chawla",save=FALSE)
harbhajan1 <- getDeliveryWickets(team="Mumbai Indians",dir=".",name="Harbhajan Singh",save=FALSE)
vinay1 <- getDeliveryWickets(team="Royal Challengers Bangalore",dir=".",name="R Vinay",save=FALSE)
sktrivedi1 <- getDeliveryWickets(team="Rajasthan Royals",dir=".",name="SK Trivedi",save=FALSE)
#Ashwin takes <6.5 deliveries for a wicket while Bravo takes around 5.5 deliveries. Don't get hung up on the .5 delivery. We can just take it that Bravo will provide a breakthrough quicker than Ashwin
par(mfrow=c(1,2))
par(mar=c(4,4,2,2))
bowlerWktsPredict(ashwin1,"R Ashwin")
bowlerWktsPredict(bravo1, "DJ Bravo")
par(mfrow=c(1,2))
par(mar=c(4,4,2,2))
bowlerWktsPredict(chawla1, "PP Chawla")
bowlerWktsPredict(harbhajan1, "Harbhajan Singh")
par(mfrow=c(1,2))
par(mar=c(4,4,2,2))
bowlerWktsPredict(vinay1, "R Vinay")
bowlerWktsPredict(sktrivedi1, "SK Trivedi")
This concludes the 4 part writeup of yorkr’s handling of IPL Twenty20’s. You can fork/clone the code from Github at yorkr.
As I mentioned earlier this bring a close to all my posts based on my R cricket package yorkr. I do have a couple of more ideas, but this will take some time I think.
Hope you have a great time with my yorkr package!
Till nxt time, adieu!
Also see