content
stringlengths 0
14.9M
| filename
stringlengths 44
136
|
---|---|
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 11 May 2020
# Function: saveAllMatchesBetween2WBBTeams
# This function saves all matches between 2 teams as a single dataframe
##################################################################################
#' @title
#' Saves all matches between 2 WBB teams as dataframe
#'
#' @description
#' This function saves all matches between 2 WBB teams as a single dataframe in the
#' current directory
#'
#' @usage
#' saveAllMatchesBetween2WBBTeams(dir=".",odir=".")
#'
#' @param dir
#' Input Directory
#'
#' @param odir
#' Output Directory to store saved matches
#'
#' @return None
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' saveAllMatchesBetween2BBLTeams(dir=".",odir=".")
#' }
#' @seealso
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{batsmanRunsVsDeliveries}}\cr
#' \code{\link{batsmanRunsVsStrikeRate}}\cr
#' \code{\link{getAllMatchesAllOpposition}}\cr
#' \code{\link{getAllMatchesBetweenTeams}}\cr
#'
#' @export
#'
saveAllMatchesBetween2WBBTeams <- function(dir=".",odir="."){
teams <-c("Adelaide Strikers", "Brisbane Heat", "Hobart Hurricanes",
"Melbourne Renegades", "Melbourne Stars", "Perth Scorchers", "Sydney Sixers",
"Sydney Thunder")
matches <- NULL
#Create all combinations of teams
for(i in seq_along(teams)){
for(j in seq_along(teams)){
if(teams[i] != teams[j]){
cat("Team1=",teams[i],"Team2=",teams[j],"\n")
tryCatch(matches <- getAllMatchesBetweenTeams(teams[i],teams[j],dir=dir,save=TRUE,odir=odir),
error = function(e) {
print("No matches")
}
)
}
}
matches <- NULL
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/saveAllMatchesBetween2WBBTeams.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 2 May 2020
# Function: saveAllMatchesBetweenTeams
# This function saves all matches between 2 teams as a single dataframe
##################################################################################
#' @title
#' Saves all matches between 2 teams as dataframe
#'
#' @description
#' This function saves all matches between 2 teams as a single dataframe in the
#' current directory
#'
#' @usage
#' saveAllMatchesBetweenTeams(dir=".",odir=".")
#'
#' @param dir
#' Input Directory to store saved matches
#'
#' @param odir
#' Output Directory to store matches between teams
#'
#' @return None
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' saveAllMatchesBetweenTeams(dir=".",odir=".")
#' }
#' @seealso
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{batsmanRunsVsDeliveries}}\cr
#' \code{\link{batsmanRunsVsStrikeRate}}\cr
#' \code{\link{getAllMatchesAllOpposition}}\cr
#' \code{\link{getAllMatchesBetweenTeams}}\cr
#'
#' @export
#'
saveAllMatchesBetweenTeams <- function(dir=".",odir="."){
teams <-c("Australia","India","Pakistan","West Indies", 'Sri Lanka',
"England", "Bangladesh","Netherlands","Scotland", "Afghanistan",
"Zimbabwe","Ireland","New Zealand","South Africa","Canada",
"Bermuda","Kenya","Hong Kong","Nepal","Oman","Papua New Guinea",
"United Arab Emirates","Namibia","Cayman Islands","Singapore",
"United States of America","Bhutan","Maldives","Botswana","Nigeria",
"Denmark","Germany","Jersey","Norway","Qatar","Malaysia","Vanuatu",
"Thailand")
matches <- NULL
#Create all combinations of teams
for(i in seq_along(teams)){
for(j in seq_along(teams)){
if(teams[i] != teams[j]){
cat("Team1=",teams[i],"Team2=",teams[j],"\n")
tryCatch(matches <- getAllMatchesBetweenTeams(teams[i],teams[j],dir=dir,save=TRUE,odir=odir),
error = function(e) {
print("No matches")
}
)
}
}
matches <- NULL
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/saveAllMatchesBetweenTeams.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 04 Dec 2021
# Function: saveAllT20BattingDetails
# This function saves all T20 batting Details
#
#
###########################################################################################
#' @title
#' Save all T20 batting details
#'
#' @description
#' This function creates a single dataframe of all T20 batting details
#' @usage
#' saveAllT20BattingDetails(teamNames,dir=".",odir=".",type="IPL",save=TRUE)
#'
#' @param teamNames
#' The team names
#'
#' @param dir
#' The output directory
#'
#' @param odir
#' The output directory
#'
#' @param type
#' T20 format
#'
#' @param save
#' To save or not
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' saveAllT20BattingDetails(teamNames,dir=".",odir=".",type="IPL",save=TRUE)
#' }
#'
#' @seealso
#' \code{\link{rankODIBowlers}}\cr
#' \code{\link{rankODIBatsmen}}\cr
#' \code{\link{rankT20Bowlers}}\cr
#' @export
#'
saveAllT20BattingDetails <- function(teamNames,dir=".",odir=".",type="IPL",save=TRUE) {
currDir= getwd()
battingDetails=batsman=runs=strikeRate=matches=meanRuns=meanSR=battingDF=val=year=NULL
teams = unlist(teamNames)
battingDF<-NULL
for(team in teams){
battingDetails <- NULL
val <- paste(team,"-BattingDetails.RData",sep="")
print(val)
tryCatch(load(val),
error = function(e) {
print("No data1")
setNext=TRUE
}
)
details <- battingDetails
battingDF <- rbind(battingDF,details)
}
if(save){
fl <-paste(odir,"/",type,"-BattingDetails.RData",sep="")
print(fl)
save(battingDF,file=fl)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/saveAllT20BattingDetails.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 08 Dec 2021
# Function: saveAllT20BowlingDetails
# This function saves all T20 batting Details
#
#
###########################################################################################
#' @title
#' Save all T20 batting details
#'
#' @description
#' This function creates a single dataframe of all T20 batting details
#' @usage
#' saveAllT20BowlingDetails(teamNames,dir=".",odir=".",type="IPL",save=TRUE)
#'
#' @param teamNames
#' The team names
#'
#' @param dir
#' The output directory
#'
#' @param odir
#' The output directory
#'
#' @param type
#' T20 format
#'
#' @param save
#' To save or not
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' saveAllT20BowlingDetails(teamNames,dir=".",odir=".",type="IPL",save=TRUE)
#' }
#'
#' @seealso
#' \code{\link{rankODIBowlers}}\cr
#' \code{\link{rankODIBatsmen}}\cr
#' \code{\link{rankT20Bowlers}}\cr
#' @export
#'
saveAllT20BowlingDetails <- function(teamNames,dir=".",odir=".",type="IPL",save=TRUE) {
currDir= getwd()
bowlingDetails=bowler=wickets=economyRate=matches=meanWickets=meanER=totalWickets=NULL
teams = unlist(teamNames)
bowlingDF<-NULL
for(team1 in teams){
bowlingDetails <- NULL
val <- paste(team1,"-BowlingDetails.RData",sep="")
print(val)
tryCatch(load(val),
error = function(e) {
print("No data1")
setNext=TRUE
}
)
details <- bowlingDetails
bowlingDF <- rbind(bowlingDF,details)
}
if(save){
fl <-paste(odir,"/",type,"-BowlingDetails.RData",sep="")
print(fl)
save(bowlingDF,file=fl)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/saveAllT20BowlingDetails.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 07 Dec 2021
# Function: saveAllT20MatchesAsDF
# This function ranks the T20 batsmen
#
#
###########################################################################################
#' @title
#' Overall picture Ranks the T20 batsmen
#'
#' @description
#' This function creates a single datframe of all T20 batsmen and then ranks them
#' @usage
#' saveAllT20MatchesAsDF(teamNames,dir=".",odir=".",type="IPL",save=TRUE)
#'
#' @param teamNames
#' The team names
#'
#' @param dir
#' The output directory
#'
#' @param odir
#' The output directory
#'
#' @param type
#' T20 format
#'
#' @param save
#' To save or not
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' saveAllT20MatchesAsDF(teamNames,dir=".",odir=".",type="IPL",save=TRUE)
#' }
#'
#' @seealso
#' \code{\link{rankODIBowlers}}\cr
#' \code{\link{rankODIBatsmen}}\cr
#' \code{\link{rankT20Bowlers}}\cr
#' @export
#'
saveAllT20MatchesAsDF <- function(teamNames,dir=".",odir=".",type="IPL",save=TRUE){
cat("Entering rank Batsmen1 \n")
currDir= getwd()
cat("T20batmandir=",currDir,"\n")
battingDetails=batsman=runs=strikeRate=matches=meanRuns=meanSR=battingDF=val=year=overs=NULL
teams = unlist(teamNames)
t20MDF <-NULL
a <- paste(dir,"/","*",".RData",sep="")
fl <- Sys.glob(a)
for(i in 1:length(fl)){
# Add try-catch to handle issues
tryCatch({
load(fl[i])
match <- overs
# If the side has not batted details will be NULL. Skip in that case
if(!is.null(dim(match))){
t20MDF <- rbind(t20MDF,match)
}else {
#print("Empty")
next
}
}, error=function(e){cat("ERROR :",conditionMessage(e), "\n")})
}
if(save==TRUE){
fl <-paste(odir,"/",type,"-MatchesDataFrame.RData",sep="")
print(fl)
save(t20MDF,file=fl)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/saveAllT20MatchesAsDF.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 20 Mar 2016
# Function: specialProc
# This is a helper function used by parseYamlOver when the over has more tan 10
# deliveries.
#
###########################################################################################
#' @title
#' Used to parse yaml file
#'
#' @description
#' This is special processing function. This is an internal function and
#' is used by convertAllYaml2RDataframes() & convertYaml2RDataframe()
#'
#' @usage
#' specialProc(dist, overset, ateam,over,str1,meta)
#'
#' @param dist
#' dist
#'
#' @param overset
#' overset
#'
#' @param ateam
#' The team
#'
#' @param over
#' over
#'
#' @param str1
#' str1
#'
#'
#' @param meta
#' The meta information of the match
#'
#' @return over
#' The dataframe of over
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#'
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Parse the yaml over
#' }
#'
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#'
# This functio is used when there are more than 10 deliveries in the over
specialProc <- function(dist, overset, ateam,over,str1,meta){
team=ball=totalRuns=rnames=batsman=bowler=nonStriker=i=NULL
byes=legbyes=noballs=wides=nonBoundary=penalty=runs=NULL
extras=wicketFielder=wicketKind=wicketPlayerOut=NULL
if(dist == 6){
names(over) <-c("batsman","bowler","nonStriker","runs","extras","totalRuns")
# Add the missing elements for extras
over$byes<-as.factor(0)
over$legbyes<-as.factor(0)
over$noballs<-as.factor(0)
over$wides<-as.factor(0)
over$nonBoundary <- as.factor(0)
over$penalty<-as.factor(0)
over$wicketFielder="nobody"
over$wicketKind="not-out"
over$wicketPlayerOut="nobody"
over$ball=gsub("\\\\.","",str1)
over$team = ateam
# Reorder the rows
over <- select(over, ball,team,batsman,bowler,nonStriker,
byes,legbyes,noballs,
wides,nonBoundary,penalty,runs,
extras,totalRuns,wicketFielder,
wicketKind,wicketPlayerOut)
over <- cbind(over,meta)
} else if(dist==7){
# The over had 7 deliveries
if(sum(grepl("\\.byes",overset$rnames))){
names(over) <-c("batsman","bowler","byes","nonStriker","runs","extras","totalRuns")
over$legbyes=as.factor(0)
over$noballs=as.factor(0)
over$wides=as.factor(0)
over$nonBoundary <- as.factor(0)
over$penalty=as.factor(0)
} else if(sum(grepl("legbyes",overset$rnames))){
names(over) <-c("batsman","bowler","legbyes","nonStriker","runs","extras","totalRuns")
over$byes=as.factor(0)
over$noballs=as.factor(0)
over$wides=as.factor(0)
over$nonBoundary <- as.factor(0)
over$penalty=as.factor(0)
} else if(sum(grepl("noballs",overset$rnames))){
names(over) <-c("batsman","bowler","noballs","nonStriker","runs","extras","totalRuns")
over$byes=as.factor(0)
over$legbyes=as.factor(0)
over$wides=as.factor(0)
over$nonBoundary <- as.factor(0)
over$penalty=as.factor(0)
} else if(sum(grepl("wides",overset$rnames))){
names(over) <-c("batsman","bowler","wides","nonStriker","runs","extras","totalRuns")
over$byes=as.factor(0)
over$legbyes=as.factor(0)
over$noballs=as.factor(0)
over$nonBoundary <- as.factor(0)
over$penalty=as.factor(0)
} else if(sum(grepl("non_boundary",overset$rnames))){
cat("sp=",i,"\n")
names(over) <-c("batsman","bowler","nonStriker","runs","extras","nonBoundary","totalRuns")
over$byes=as.factor(0)
over$legbyes=as.factor(0)
over$wides=as.factor(0)
over$noballs=as.factor(0)
over$penalty=as.factor(0)
} else if(sum(grepl("penalty",overset$rnames))){
names(over1) <-c("batsman","bowler","penalty","nonStriker","runs","extras","totalRuns")
over$byes=as.factor(0)
over$legbyes=as.factor(0)
over$noballs=as.factor(0)
over$wides=as.factor(0)
over$nonBoundary <- as.factor(0)
}
# Add missing elements
over$wicketFielder="nobody"
over$wicketKind="not-out"
over$wicketPlayerOut="nobody"
over$ball=gsub("\\\\.","",str1)
over$team = ateam
# Reorder
over <- select(over, ball,team,batsman,bowler,nonStriker,
byes,legbyes,noballs,
wides,nonBoundary,penalty,runs,
extras,totalRuns,wicketFielder,
wicketKind,wicketPlayerOut)
#over <- over[,c(14,15,1,2,3,4,5,6,7,8,9,10,11,12,13)]
over <- cbind(over,meta)
#cat("Hhhh",dim(over),"\n")
} else if(dist ==8){
names(over) <-c("batsman","bowler","nonStriker","runs","extras","totalRuns","wicketKind","wicketPlayerOut")
# Add the missing elements for extras
over$byes<-as.factor(0)
over$legbyes<-as.factor(0)
over$noballs<-as.factor(0)
over$wides<-as.factor(0)
over$nonBoundary <- as.factor(0)
over$penalty<-as.factor(0)
over$wicketFielder="nobody"
over$ball=gsub("\\\\.","",str1)
over$team = ateam
# Reorder
over <- select(over, ball,team,batsman,bowler,nonStriker,
byes,legbyes,noballs,
wides,nonBoundary,penalty,runs,
extras,totalRuns,wicketFielder,
wicketKind,wicketPlayerOut)
over <- cbind(over,meta)
} else if(dist ==9){
names(over) <-c("batsman","bowler","nonStriker","runs","extras","totalRuns",
"wicketFielder","wicketKind","wicketPlayerOut")
# Add the missing elements for extras
over$byes<-as.factor(0)
over$legbyes<-as.factor(0)
over$noballs<-as.factor(0)
over$wides<-as.factor(0)
over$nonBoundary <- as.factor(0)
over$penalty<-as.factor(0)
over$ball=gsub("\\\\.","",str1)
over$team = ateam
over <- select(over, ball,team,batsman,bowler,nonStriker,
byes,legbyes,noballs,
wides,nonBoundary,penalty,runs,
extras,totalRuns,wicketFielder,
wicketKind,wicketPlayerOut)
over <- cbind(over,meta)
} else if(dist == 10){
if(sum(grepl("\\.byes",overset$rnames))){
names(over) <-c("batsman","bowler","byes","nonStriker","runs","extras","totalRuns",
"wicketFielder","wicketKind","wicketPlayerOut")
over$legbyes=as.factor(0)
over$noballs=as.factor(0)
over$wides=as.factor(0)
over$nonBoundary <- as.factor(0)
over$penalty<-as.factor(0)
} else if(sum(grepl("legbyes",overset$rnames))){
names(over) <-c("batsman","bowler","legbyes","nonStriker","runs","extras","totalRuns",
"wicketFielder","wicketKind","wicketPlayerOut")
over$byes=as.factor(0)
over$noballs=as.factor(0)
over$wides=as.factor(0)
over$nonBoundary <- as.factor(0)
over$penalty<-as.factor(0)
} else if(sum(grepl("noballs",overset$rnames))){
names(over) <-c("batsman","bowler","noballs","nonStriker","runs","extras","totalRuns",
"wicketFielder","wicketKind","wicketPlayerOut")
over$byes=as.factor(0)
over$legbyes=as.factor(0)
over$wides=as.factor(0)
over$nonBoundary <- as.factor(0)
over$penalty<-as.factor(0)
} else if(sum(grepl("wides",overset$rnames))){
names(over) <-c("batsman","bowler","wides","nonStriker","runs","extras","totalRuns",
"wicketFielder","wicketKind","wicketPlayerOut")
over$byes=as.factor(0)
over$legbyes=as.factor(0)
over$noballs=as.factor(0)
over$nonBoundary <- as.factor(0)
over$penalty<-as.factor(0)
} else if(sum(grepl("non_boundary",overset$rnames))){
cat("sp=",i,"\n")
names(over) <-c("batsman","bowler","nonStriker","runs","extras","nonBoundary","totalRuns")
over$byes=as.factor(0)
over$legbyes=as.factor(0)
over$wides=as.factor(0)
over$noballs=as.factor(0)
over$penalty=as.factor(0)
over$penalty<-as.factor(0)
} else if(sum(grepl("penalty",overset$rnames))){
names(over) <-c("batsman","bowler","penalty","nonStriker","runs","extras","totalRuns")
over$byes=as.factor(0)
over$legbyes=as.factor(0)
over$noballs=as.factor(0)
over$wides=as.factor(0)
over$nonBoundary=as.factor(0)
over$penalty<-as.factor(0)
}
over$ball=gsub("\\\\.","",str1)
over$team = ateam
over <- select(over, ball,team,batsman,bowler,nonStriker,
byes,legbyes,nonBoundary,penalty,noballs,
wides,runs,
extras,totalRuns,wicketFielder,
wicketKind,wicketPlayerOut)
over <- cbind(over,meta)
print("Ho!")
}
#cat("returning",dim(over),"\n")
over
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/specialProc.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 24 Mar 2016
# Function: teamBatsmenPartnershipAllOppnAllMatches
# This function computes the partnetship of the batsman against all opposition
#
#
###########################################################################################
#' @title
#' Team batting partnership in all matches all oppositions
#'
#' @description
#' This function computes the batting partnership of a team againt all oppositions in all matches
#' This function returns a dataframe which is a summary of the batsman with the highest partnerships
#' or the partnership of an individual batsman
#'
#' @usage
#' teamBatsmenPartnershipAllOppnAllMatches(matches,theTeam,report="summary")
#'
#' @param matches
#' All the matches of the team against all oppositions
#'
#' @param theTeam
#' The team for which the the batting partnerships are sought
#'
#'@param report
#' if the report="summary" then the data frame returned gives a list of the batsmen with the highest
#' partnerships. If report="detailed" then the detailed breakup of the partnership is returned.
#'
#' @return partnerships
#' The data frame with the partnerships
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get all matches for team India against all oppositions
#' m <-teamBattingScorecardAllOppnAllMatches(matches,theTeam="India")
#' # Get the summary report
#' teamBatsmenPartnershipAllOppnAllMatches(matches,theTeam='India')
#'
#' # Get the detailed report
#' teamBatsmenPartnershipAllOppnAllMatches(matches,theTeam='India',report="detailed")
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenVsBowlersOppnAllMatches}}\cr
#'
#' @export
#'
teamBatsmenPartnershipAllOppnAllMatches <- function(matches,theTeam,report="summary"){
team=batsman=nonStriker=runs=partnershipRuns=totalRuns=NULL
ggplotly=NULL
a <-filter(matches,team==theTeam)
#Get partnerships
df <- data.frame(summarise(group_by(a,batsman,nonStriker),sum(runs)))
names(df) <- c("batsman","nonStriker","partnershipRuns")
b <- summarise(group_by(df,batsman),totalRuns=sum(partnershipRuns))
c <- arrange(b,desc(totalRuns))
d <- full_join(df,c,by="batsman")
if(report == "detailed"){
partnerships <- arrange(d,desc(totalRuns))
} else{
partnerships <- arrange(c,desc(totalRuns))
}
partnerships
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBatsmenPartnershipAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 24 Mar 2016
# Function: teamBatsmenPartnershipAllOppnAllMatchesPlot
# This function computes the batting partnerships of a team against all oppositions and
# also the partenerships of th eopposition against this team
#
#
###########################################################################################
#' @title
#' Plots team batting partnership all matches all oppositions
#'
#' @description
#' This function plots the batting partnership of a team againt all oppositions in all matches
#' This function also returns a dataframe with the batting partnerships
#'
#' @usage
#' teamBatsmenPartnershipAllOppnAllMatchesPlot(matches,theTeam,main,plot=1)
#'
#' @param matches
#' All the matches of the team against all oppositions
#'
#' @param theTeam
#' The team for which the the batting partnerships are sought
#'
#' @param main
#' The main team for which the the batting partnerships are sought
#'
#'@param plot
#' Whether the partnerships have top be rendered as a plot. Plot=1 (static),plot=2(interactive),plot=3(table)
#'
#' @return None or partnerships
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get all matches for team India against all oppositions
#' d <- teamBatsmanVsBowlersAllOppnAllMatchesRept(matches,"India",rank=1,dispRows=50)
#' #Plot the partnerships
#' teamBatsmenVsBowlersAllOppnAllMatchesPlot(d)
#'
#' #Do not plot but get the dataframe
#' e <- teamBatsmenVsBowlersAllOppnAllMatchesPlot(d,plot=FALSE)
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatches}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenVsBowlersOppnAllMatches}}\cr
#'
#' @export
#'
teamBatsmenPartnershipAllOppnAllMatchesPlot <- function(matches,theTeam,main,plot=1){
team=batsman=nonStriker=runs=partnershipRuns=totalRuns=NULL
ggplotly=NULL
a <- NULL
a <-filter(matches,team==theTeam)
#Get partnerships
df <- data.frame(summarise(group_by(a,batsman,nonStriker),sum(runs)))
names(df) <- c("batsman","nonStriker","runs")
# Filter all rows where runs is 0. Problem when t2="Sri Lanka"
# Sehwag and Ganguly show up as partnerships with runs=0
#*****Check******** when the line below is removed
df <- filter(df,runs!=0)
df <- arrange(df,desc(runs))
if(plot == 1){ #ggplot2
if(theTeam==main){
plot.title <- paste(theTeam," batting partnerships")
}else if(theTeam != main){
plot.title <- paste(theTeam," batting partnerships against ", main)
}
ggplot(data=df,aes(x=batsman,y=runs,fill=nonStriker))+
geom_bar(data=df,stat="identity") +
xlab("Batsman") + ylab("Partnership runs") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),"")))) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
} else if(plot == 2){ #ggplotly
if(theTeam==main){
plot.title <- paste(theTeam," batting partnerships")
}else if(theTeam != main){
plot.title <- paste(theTeam," batting partnerships against ", main)
}
g <- ggplot(data=df,aes(x=batsman,y=runs,fill=nonStriker))+
geom_bar(data=df,stat="identity") +
xlab("Batsman") + ylab("Partnership runs") +
ggtitle(plot.title) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
ggplotly(g)
} else{
df
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBatsmenPartnershipAllOppnAllMatchesPlot.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 21 Mar 2016
# Function: teamBatsmenPartnershipMatch
# This function computes and displays the partnership details in a match. The output
# can either be a plot or the data frame used in the plot
#
###########################################################################################
#' @title
#' Team batting partnerships of batsmen in a match
#'
#' @description
#' This function plots the partnerships of batsmen in a match against an opposition or it can return
#' the data frame
#'
#' @usage
#' teamBatsmenPartnershipMatch(match,theTeam,opposition, plot=1)
#'
#' @param match
#' The match between the teams
#'
#' @param theTeam
#' The team for which the the batting partnerships are sought
#'
#' @param opposition
#' The opposition team
#'
#' @param plot
#' Plot=1 (static),plot=2(interactive),plot=3(table)
#'
#' @return df
#' The data frame of the batsmen partnetships
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get athe match between England and Pakistan
#' a <- getMatchDetails("England","Pakistan","2006-09-05",dir="../temp")
#' batsmenPartnershipMatch(a,"Pakistan","England")
#' batsmenPartnershipMatch(a,"England","Pakistan", plot=TRUE)
#' m <-batsmenPartnershipMatch(a,"Pakistan","England", plot=FALSE)
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenVsBowlersOppnAllMatches}}\cr
#'
#' @export
#'
teamBatsmenPartnershipMatch <- function(match,theTeam,opposition,plot=1){
team=batsman=nonStriker=runs=runsScored=NULL
ggplotly=NULL
a <-filter(match,team==theTeam)
# Group batsman with non strikers and compute partnerships
df <- data.frame(summarise(group_by(a,batsman,nonStriker),sum(runs)))
names(df) <- c("batsman","nonStriker","runs")
print(dim(df))
if(plot==1){ #ggplot2
plot.title <- paste(theTeam,"Batting partnership in match (vs.",opposition,")")
ggplot(data=df,aes(x=batsman,y=runs,fill=nonStriker))+
geom_bar(data=df,stat="identity") +
xlab("Batmen") + ylab("Runs Scored") +
labs(title=plot.title,subtitle="Data source:http://cricsheet.org/") +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
} else if(plot == 2){ #ggplotly
plot.title <- paste(theTeam,"Batting partnership in match (vs.",opposition,")")
g <- ggplot(data=df,aes(x=batsman,y=runs,fill=nonStriker))+
geom_bar(data=df,stat="identity") +
xlab("Batmen") + ylab("Runs Scored") +
labs(title=plot.title,subtitle="Data source:http://cricsheet.org/") +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
ggplotly(g)
}
else{
# Output dataframe
df
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBatsmenPartnershipMatch.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 22 Mar 2016
# Function: teamBatsmenPartnershiOppnAllMatches
# This function computes the batting partnership of a team in all matches against
# an opposition. The report generated can be detailed or a summary
#
###########################################################################################
#' @title
#' Team batting partnership against a opposition all matches
#'
#' @description
#' This function computes the performance of batsmen against all bowlers of an oppositions in all matches. This
#' function returns a dataframe
#'
#' @usage
#' teamBatsmenPartnershiOppnAllMatches(matches,theTeam,report="summary")
#'
#' @param matches
#' All the matches of the team against the oppositions
#'
#' @param theTeam
#' The team for which the the batting partnerships are sought
#'
#' @param report
#' If the report="summary" then the list of top batsmen with the highest partnerships is displayed. If
#' report="detailed" then the detailed break up of partnership is returned as a dataframe
#'
#' @return partnerships
#' The data frame of the partnerships
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get all matches for team India against all oppositions
#' matches <- getAllMatchesBetweenTeams("Australia","India",dir="../data")
#' # You can also directly load the data
#' #load("India-Australia-allMatches.RData")
#'
#' m <-teamBatsmenPartnershiOppnAllMatches(a,'India',report="summary")
#' m <-teamBatsmenPartnershiOppnAllMatches(a,'Australia',report="detailed")
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBowlersVsBatsmenMatch}}\cr
#' \code{\link{teamBattingScorecardMatch}}\cr
#'
#' @export
#'
teamBatsmenPartnershiOppnAllMatches <- function(matches,theTeam,report="summary"){
team=batsman=nonStriker=partnershipRuns=runs=totalRuns=NULL
a <-filter(matches,team==theTeam)
#Get partnerships
df <- data.frame(summarise(group_by(a,batsman,nonStriker),sum(runs)))
names(df) <- c("batsman","nonStriker","partnershipRuns")
b <- summarise(group_by(df,batsman),totalRuns=sum(partnershipRuns))
c <- arrange(b,desc(totalRuns))
d <- full_join(df,c,by="batsman")
if(report == "detailed"){
partnerships <- arrange(d,desc(totalRuns))
} else{
partnerships <- arrange(c,desc(totalRuns))
}
partnerships
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBatsmenPartnershipOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 22 Mar 2016
# Function: teamBatsmenPartnershipOppnAllMatchesChart
# This function computes the batting partnership of a team in all matches against
# an opposition. The report generated can be detailed or a summary
#
###########################################################################################
#' @title
#' Plot of team partnership all matches against an opposition
#'
#' @description
#' This function plots the batting partnership of a team againt all oppositions in all matches
#' This function also returns a dataframe with the batting partnerships
#'
#' @usage
#' teamBatsmenPartnershipOppnAllMatchesChart(matches,main,opposition, plot=1)
#'
#' @param matches
#' All the matches of the team against all oppositions
#'
#' @param main
#' The main team for which the the batting partnerships are sought
#'
#' @param opposition
#' The opposition team for which the the batting partnerships are sought
#'
#' @param plot
#' Plot=1 (static),plot=2(interactive),plot=3(table)
#'
#' @return None or partnerships
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get all matches for team India against all oppositions
#' d <- teamBatsmenVsBowlersAllOppnAllMatchesRept(matches,"India",rank=1,dispRows=50)
#' #Plot the partnerships
#' teamBatsmenVsBowlersAllOppnAllMatchesPlot(d)
#'
#' #Do not plot but get the dataframe
#' e <- teamBatsmenVsBowlersAllOppnAllMatchesPlot(d,plot=FALSE)
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatches}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenVsBowlersOppnAllMatches}}\cr
#'
#' @export
#'
teamBatsmenPartnershipOppnAllMatchesChart <- function(matches,main,opposition,plot=1){
team=batsman=nonStriker=runs=partnershipRuns=totalRuns=NULL
ggplotly=NULL
a <-filter(matches,team==main)
#Get partnerships
df <- data.frame(summarise(group_by(a,batsman,nonStriker),sum(runs)))
names(df) <- c("batsman","nonStriker","runs")
df <- arrange(df,desc(runs))
print("here")
cat("plot=")
plot.title = paste(main," Batting partnership ","(against ",opposition," all matches)",sep="")
# Plot the data
if(plot == 1){ #ggplot2
ggplot(data=df,aes(x=batsman,y=runs,fill=nonStriker))+
geom_bar(data=df,stat="identity") +
xlab("Batsman") + ylab("Partnership runs") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),"")))) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
} else if(plot == 2){ #ggplotly
g <- ggplot(data=df,aes(x=batsman,y=runs,fill=nonStriker))+
geom_bar(data=df,stat="identity") +
xlab("Batsman") + ylab("Partnership runs") +
ggtitle(plot.title) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
ggplotly(g)
} else{
df
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBatsmenPartnershipOppnAllMatchesChart.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 25 Mar 2016
# Function: teamBatsmenVsBowlersAllOppnAllMatchesRept
# This function computes performance of batsmen/batsman against bowlers of the opposition.
# It provides the names of the bowlers against whom the batsman scored the most.
# We can the over all performance of the team or the individual performances of the batsman
# If rank=10 then the overall performance of the team is displayed
# For a rank'n' the performance of the batsman at that rank against bowlers is displayed
###########################################################################################
#' @title
#' Report of team batsmen vs bowlers in all matches all oppositions
#'
#' @description
#' This function computes the performance of batsmen against all bowlers of all oppositions in all matches
#'
#' @usage
#' teamBatsmenVsBowlersAllOppnAllMatchesRept(matches,theTeam,rank=0,dispRows=50)
#'
#' @param matches
#' All the matches of the team against all oppositions
#'
#' @param theTeam
#' The team for which the the batting partnerships are sought
#'
#' @param rank
#' if the rank=0 then the data frame returned gives a summary list of the batsmen with the highest
#' runs against bowlers. If rank=N (where N=1,2,3...) then the detailed breakup of the batsman and the runs
#' scored against each bowler is returned
#'
#' @param dispRows
#' The number of rows to be returned
#'
#' @return h
#' The data frame of the batsman and the runs against bowlers
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get all matches for team India against all oppositions
#' m <-teamBattingScorecardAllOppnAllMatches(matches,theTeam="India")
#' # Get the summary report
#' teamBatsmenVsBowlersAllOppnAllMatchesRept(matches,"India",rank=0)
#' #Get detailed report
#' teamBatsmenVsBowlersAllOppnAllMatchesRept(matches,"India",rank=1,dispRows=50)
#'
#' teamBatsmenVsBowlersAllOppnAllMatchesRept(matches,"Pakistan",rank=0)
#' teamBatsmenVsBowlersAllOppnAllMatchesRept(matches,"England",rank=1)
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenVsBowlersOppnAllMatches}}\cr
#'
#' @export
#'
teamBatsmenVsBowlersAllOppnAllMatchesRept <- function(matches,theTeam,rank=0,dispRows=50)
{
team=batsman=bowler=runs=runsScored=NULL
ggplotly=NULL
a <-filter(matches,team==theTeam)
b <-summarise(group_by(a,batsman,bowler),sum(runs))
names(b) <- c("batsman","bowler","runs")
c <- summarise(b,runsScored=sum(runs))
d <- arrange(c,desc(runsScored))
# If rank == 0 thne display top batsman with best performance
if(rank == 0){
f <- d
} else {
# display dispRows for selected batsman with rank and runs scored against opposing bowlers
bman <- d[rank,]
f <- filter(b,batsman==bman$batsman)
f <- arrange(f,desc(runs))
# Output only dispRows
f <- f[1:dispRows,]
}
g <- complete.cases(f)
h <- f[g,]
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBatsmenVsBowlersAllOppnAllMatchesRept.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 21 Mar 2016
# Function: teamBatsmenVsBowlersMatch
# This function computes the performance of batsmen against different bowlers.
# The user has a choice of either taking the output as a plot or as a dataframe
#
###########################################################################################
#' @title
#' Team batsmen against bowlers in a match
#'
#' @description
#' This function plots the performance of batsmen versus bowlers in a match or it can return
#' the data frame
#'
#' @usage
#' teamBatsmenVsBowlersMatch(match,theTeam,opposition, plot=1)
#'
#' @param match
#' The match between the teams
#'
#' @param theTeam
#' The team for which the the batting partnerships are sought
#'
#' @param opposition
#' The opposition team
#'
#' @param plot
#' lot=1 (static),plot=2(interactive),plot=3(table)
#'
#' @return b
#' The data frame of the batsmen vs bowlers performance
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get athe match between England and Pakistan
#' a <- getMatchDetails("England","Pakistan","2006-09-05",dir="../temp")
#' batsmenVsBowlersMatch(a,'Pakistan','England', plot=TRUE)
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBattingScorecardMatch}}\cr
#'
#' @export
#'
teamBatsmenVsBowlersMatch <- function(match,theTeam,opposition, plot=1)
{
team=batsman=bowler=runs=runsConceded=NULL
ggplotly=NULL
a <-filter(match,team==theTeam)
# Summarise the performance of the batsmen against the bowlers vs total runs scored
b <-summarise(group_by(a,batsman,bowler),sum(runs))
names(b) <- c("batsman","bowler","runsConceded")
if(plot == 1){ #ggplot2
plot.title <- paste(theTeam,"Batsmen vs Bowlers in Match (vs.",opposition,")")
# Plot the performance of the batsmen as a facted grid
ggplot(data=b,aes(x=bowler,y=runsConceded,fill=factor(bowler))) +
facet_grid(~ batsman) + geom_bar(stat="identity") +
xlab("Opposition bowlers") + ylab("Runs scored") +
ggtitle('Batsmen vs Bowlers in Match') +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),"")))) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
} else if(plot == 2){ #ggplotly
plot.title <- paste(theTeam,"Batsmen vs Bowlers in Match (vs.",opposition,")")
# Plot the performance of the batsmen as a facted grid
g <- ggplot(data=b,aes(x=bowler,y=runsConceded,fill=factor(bowler))) +
facet_grid(~ batsman) + geom_bar(stat="identity") +
xlab("Opposition bowlers") + ylab("Runs scored") +
ggtitle('Batsmen vs Bowlers in Match') +
ggtitle(plot.title) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
ggplotly(g)
}
else{
b
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBatsmenVsBowlersMatch.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 22 Mar 2016
# Function: teamBatsmenVsBowlersOppnAllMatches
# This function computes the best performing batsman against an opposition's bowlers
# in all matches with this team.The top 5 batsman are displayed by default
#
#
###########################################################################################
#' @title
#' Team batsmen vs bowlers all matches of an opposition
#'
#' @description
#' This function computes the performance of batsmen against the bowlers of an oppositions in all matches
#'
#' @usage
#' teamBatsmenVsBowlersOppnAllMatches(matches,main,opposition,plot=1,top=5)
#'
#' @param matches
#' All the matches of the team against one specific opposition
#'
#' @param main
#' The team for which the the batting partnerships are sought
#'
#' @param opposition
#' The opposition team
#'
#' @param plot
#' lot=1 (static),plot=2(interactive),plot=3(table)
#'
#' @param top
#' The number of players to be plotted or returned as a dataframe. The default is 5
#'
#'
#' @return None or dataframe
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get all matches for team India against an opposition
#' matches <- getAllMatchesBetweenTeams("Australia","India",dir="../data")
#'
#' # Get the performance of India batsman against Australia in all matches
#' teamBatsmenVsBowlersOppnAllMatches(a,"India","Australia")
#'
#' # Display top 3
#' teamBatsmanVsBowlersOppnAllMatches(a,"Australia","India",top=3)
#'
#' # Get top 10 and do not plot
#' n <- teamBatsmenVsBowlersOppnAllMatches(a,"Australia","India",top=10,plot=FALSE)
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenVsBowlersOppnAllMatches}}\cr
#'
#' @export
#'
teamBatsmenVsBowlersOppnAllMatches <- function(matches,main,opposition,plot=1,top=5){
team=batsman=bowler=runs=runsScored=NULL
ggplotly=NULL
a <-filter(matches,team==main)
b <-summarise(group_by(a,batsman,bowler),sum(runs))
names(b) <- c("batsman","bowler","runs")
c <- summarise(b,runsScored=sum(runs))
d <- arrange(c,desc(runsScored))
# Pick 9 highest run givers
d <- head(d,top)
batsmen <- as.character(d$batsman)
e <- NULL
for(i in 1:length(batsmen)){
f <- filter(b,batsman==batsmen[i])
e <- rbind(e,f)
}
if(plot == 1){ #ggplot2
plot.title = paste(main," Batsmen vs bowlers"," (against ",opposition," all matches)",sep="")
ggplot(data=e,aes(x=bowler,y=runs,fill=factor(bowler))) +
facet_grid(~ batsman) + geom_bar(stat="identity") +
xlab("Bowler") + ylab("Runs Scored") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),"")))) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
} else if(plot == 2){ #ggplotly
plot.title = paste(main," Batsmen vs bowlers"," (against ",opposition," all matches)",sep="")
g <- ggplot(data=e,aes(x=bowler,y=runs,fill=factor(bowler))) +
facet_grid(~ batsman) + geom_bar(stat="identity") +
xlab("Bowler") + ylab("Runs Scored") +
ggtitle(plot.title) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
ggplotly(g,height=500)
}
else{
e
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBatsmenVsBowlersOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 25 Mar 2016
# Function: teamBatsmenVsBowlersAllOppnAllMatchesPlot
# This function computes performance of batsmen/batsman against bowlers of the opposition.
# It provides the names of the bowlers against whom the batsman scored the most.
# This is plotted as a chart
###########################################################################################
#' @title
#' Plot of Team batsmen vs bowlers against all opposition all matches
#'
#' @description
#' This function computes the performance of batsmen against all bowlers of all oppositions in all matches.
#' The data frame can be either plotted or returned to the user
#'
#' @usage
#' teamBatsmenVsBowlersAllOppnAllMatchesPlot(df,plot=1)
#'
#' @param df
#' The dataframe of all the matches of the team against all oppositions
#'
#' @param plot
#' plot=1 (static),plot=2(interactive), plot=3 (table)
#'
#'
#' @return None or dataframe
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get all matches for team India against all oppositions in all matches
#' matches <-getAllMatchesAllOpposition("India",dir="../data/",save=TRUE)
#'
#' # Also load directly from file
#' #load("allMatchesAllOpposition-India.RData")
#'
#' d <- teamBatsmanVsBowlersAllOppnAllMatchesRept(matches,"India",rank=1,dispRows=50)
#' teamBatsmenVsBowlersAllOppnAllMatchesPlot(d)
#' e <- teamBatsmenVsBowlersAllOppnAllMatchesPlot(d,plot=FALSE)
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenVsBowlersOppnAllMatches}}\cr
#'
#' @export
#'
teamBatsmenVsBowlersAllOppnAllMatchesPlot <- function(df,plot=1)
{
runs=bowler=NULL
ggplotly=NULL
bman <- df$batsman
if(plot == 1){ #ggplot2
plot.title <- paste(bman,"-Performances against all bowlers")
ggplot(data=df,aes(x=bowler,y=runs,fill=factor(bowler))) +
facet_grid(~ batsman) + geom_bar(stat="identity") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),"")))) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
} else if(plot == 2){ #ggplotly
plot.title <- paste(bman,"-Performances against all bowlers")
g <- ggplot(data=df,aes(x=bowler,y=runs,fill=factor(bowler))) +
facet_grid(~ batsman) + geom_bar(stat="identity") +
ggtitle(plot.title) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
ggplotly(g,height=500)
}else{
df
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBatsmenvsBowlersAllOppnAllMatchesPlot.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 25 Mar 2016
# Function: teamBattingPerfDetails
# This function get the overall team batting details of the matcjh
#
###########################################################################################
#' @title
#' Gets the team batting details.
#'
#' @description
#' This function gets the team batting detals
#'
#' @usage
#' teamBattingPerfDetails(match,theTeam,includeInfo=FALSE)
#'
#' @param match
#' The match between the teams
#'
#' @param theTeam
#' The team for which the the batting partnerships are sought
#'
#' @param includeInfo
#' Whether to include venue,date, winner and result
#'
#' @return df
#' dataframe
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' #teamBattingPerfDetails()
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBattingScorecardMatch}}\cr
#'
#'
#'
teamBattingPerfDetails <- function(match,theTeam,includeInfo=FALSE){
team=batsman=runs=fours=sixes=NULL
byes=legbyes=noballs=wides=bowler=wicketFielder=NULL
wicketKind=wicketPlayerOut=NULL
# Initialise to NULL
details <- NULL
a <-filter(match,team==theTeam)
sz <- dim(a)
if(sz[1] == 0){
#cat("No batting records.\n")
return(NULL)
}
b <- select(a,batsman,runs)
names(b) <-c("batsman","runs")
#Compute the number of 4s
c <-
b %>%
mutate(fours=(runs>=4 & runs <6)) %>%
filter(fours==TRUE)
# Group by batsman. Count 4s
d <- summarise(group_by(c, batsman),fours=n())
# Get the total runs for each batsman
e <-summarise(group_by(a,batsman),sum(runs))
names(b) <-c("batsman","runs")
details <- full_join(e,d,by="batsman")
names(details) <-c("batsman","runs","fours")
# Compute number of 6's
f <-
b %>%
mutate(sixes=(runs ==6)) %>%
filter(sixes == TRUE)
# Group by batsman. COunt 6s
g <- summarise(group_by(f, batsman),sixes=n())
names(g) <-c("batsman","sixes")
# Full join with 4s and 6s
details <- full_join(details,g,by="batsman")
# Count the balls played by the batsman
ballsPlayed <-
a %>%
select(batsman,byes,legbyes,wides,noballs,runs) %>%
filter(wides ==0,noballs ==0,byes ==0,legbyes == 0) %>%
select(batsman,runs)
ballsPlayed<- summarise(group_by(ballsPlayed,batsman),count=n())
names(ballsPlayed) <- c("batsman","ballsPlayed")
# Create a data frame
details <- full_join(details,ballsPlayed,by="batsman")
# If there are NAs then replace with 0's
if(sum(is.na(details$fours)) != 0){
details[is.na(details$fours),]$fours <- 0
}
if(sum(is.na(details$sixes)) != 0){
details[is.na(details$sixes),]$sixes <- 0
}
details <- select(details,batsman,ballsPlayed,fours,sixes,runs)
#Calculate strike rate
details <- mutate(details,strikeRate=round(((runs/ballsPlayed)*100),2))
w <- filter(a,wicketKind !="not-out" | wicketPlayerOut != "nobody" )
# Remove unnecessary factors
w$wicketPlayerOut <-factor(w$wicketPlayerOut)
wkts <- select(w,batsman,bowler,wicketFielder,wicketKind,wicketPlayerOut)
details <- full_join(details,wkts,by="batsman")
# Set as character to be able to assign value
details$wicketPlayerOut <- as.character(details$wicketPlayerOut)
details$wicketKind <- as.character(details$wicketKind)
details$wicketFielder <- as.character(details$wicketFielder)
details$bowler <- as.character(details$wicketFielder)
# Set the NA columns in wicketPlayerOut with notOut
# Also set the other columns for this row
if(sum(is.na(details$wicketPlayerOut))!= 0){
details[is.na(details$wicketPlayerOut),]$wicketPlayerOut="notOut"
details[is.na(details$wicketKind),]$wicketKind="notOut"
details[is.na(details$wicketFielder),]$wicketFielder="nobody"
details[is.na(details$bowler),]$bowler="nobody"
}
# Determine the opposition
t <- match$team != theTeam
# Pick the 1st element
t1 <- match$team[t]
opposition <- as.character(t1[1])
if(includeInfo == TRUE) {
details$date <- a$date[1]
details$venue <- a$venue[1]
details$opposition <- opposition
details$winner <- a$winner[1]
details$result <- a$result[1]
}
details
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBattingPerfDetails.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 24 Mar 2016
# Function: teamBattingScorecardAllOppnAllMatches
# This function computes the performances of the teams batsman against all opposition in
# all matches
#
#
###########################################################################################
#' @title
#' Team batting scorecard against all oppositions in all matches
#'
#' @description
#' This function omputes and returns the batting scorecard of a team in all matches against all
#' oppositions. The data frame has the ball played, 4's,6's and runs scored by batsman
#'
#' @usage
#' teamBattingScorecardAllOppnAllMatches(matches,theTeam)
#'
#' @param matches
#' All matches of the team in all matches with all oppositions
#'
#' @param theTeam
#' The team for which the the batting partnerships are sought
#'
#'
#' @return details
#' The data frame of the scorecard of the team in all matches against all oppositions
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get all matches between India with all oppositions
#' matches <-getAllMatchesAllOpposition("India",dir="../data/",save=TRUE)
#'
#' # This can also be loaded from saved file
#' # load("allMatchesAllOpposition-India.RData")
#'
#' # Top batsman is displayed in descending order of runs
#' teamBattingScorecardAllOppnAllMatches(matches,theTeam="India")
#'
#' # The best England players scorecard against India is shown
#' teamBattingScorecardAllOppnAllMatches(matches,theTeam="England")
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBowlingWicketRunsAllOppnAllMatches}}
#'
#' @export
#'
teamBattingScorecardAllOppnAllMatches <- function(matches,theTeam){
team=batsman=runs=fours=sixes=NULL
byes=legbyes=noballs=wides=NULL
a <-filter(matches,team==theTeam)
b <- select(a,batsman,runs)
names(b) <-c("batsman","runs")
#Compute the number of 4s
c <-
b %>%
mutate(fours=(runs>=4 & runs <6)) %>%
filter(fours==TRUE)
# Group by batsman. Count 4s
d <- summarise(group_by(c, batsman),fours=n())
# Get the total runs for each batsman
e <-summarise(group_by(a,batsman),sum(runs))
names(b) <-c("batsman","runs")
details <- full_join(e,d,by="batsman")
names(details) <-c("batsman","runs","fours")
f <-
b %>%
mutate(sixes=(runs ==6)) %>%
filter(sixes == TRUE)
# Group by batsman. COunt 6s
g <- summarise(group_by(f, batsman),sixes=n())
names(g) <-c("batsman","sixes")
#Full join with 4s and 6s
details <- full_join(details,g,by="batsman")
# Count the balls played by the batsman
ballsPlayed <-
a %>%
select(batsman,byes,legbyes,wides,noballs,runs) %>%
filter(wides ==0,noballs ==0,byes ==0,legbyes == 0) %>%
select(batsman,runs)
ballsPlayed<- summarise(group_by(ballsPlayed,batsman),count=n())
names(ballsPlayed) <- c("batsman","ballsPlayed")
details <- full_join(details,ballsPlayed,by="batsman")
cat("Total=",sum(details$runs),"\n")
details <- arrange(details,desc(runs),desc(sixes),desc(fours))
details <- select(details,batsman,ballsPlayed,fours,sixes,runs)
details
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBattingScorecardAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 20 Mar 2016
# Function: teamBattingScorecardMatch
# This function gets the batting scorecard of team in a match. The result is
# returned as a data frame
#
###########################################################################################
#' @title
#' Team batting scorecard of a team in a match
#'
#' @description
#' This function computes returns the batting scorecard (runs, fours, sixes, balls played) for the
#' team
#' @usage
#' teamBattingScorecardMatch(match,theTeam)
#'
#' @param match
#' The match for which the score card is required e.g.
#'
#' @param theTeam
#' Team for which scorecard required
#'
#' @return scorecard
#' A data frame with the batting scorecard
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' a <- getMatchDetails("England","Pakistan","2006-09-05",dir="../temp")
#' teamBowlingScorecardMatch(a,'England')
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatches}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#'
#' @export
#'
teamBattingScorecardMatch <- function(match,theTeam){
team=batsman=runs=fours=sixes=NULL
byes=legbyes=noballs=wides=NULL
a <-filter(match,team==theTeam)
sz <- dim(a)
if(sz[1] == 0){
cat("No batting records.\n")
return(NULL)
}
b <- select(a,batsman,runs)
names(b) <-c("batsman","runs")
#Compute the number of 4s
c <-
b %>%
mutate(fours=(runs>=4 & runs <6)) %>%
filter(fours==TRUE)
# Group by batsman. Count 4s
d <- summarise(group_by(c, batsman),fours=n())
# Get the total runs for each batsman
e <-summarise(group_by(a,batsman),sum(runs))
names(b) <-c("batsman","runs")
details <- full_join(e,d,by="batsman")
names(details) <-c("batsman","runs","fours")
f <-
b %>%
mutate(sixes=(runs ==6)) %>%
filter(sixes == TRUE)
# Group by batsman. oOunt 6s
g <- summarise(group_by(f, batsman),sixes=n())
names(g) <-c("batsman","sixes")
#Full join with 4s and 6s
details <- full_join(details,g,by="batsman")
# Count the balls played by the batsman
ballsPlayed <-
a %>%
select(batsman,byes,legbyes,wides,noballs,runs) %>%
filter(wides ==0,noballs ==0,byes ==0,legbyes == 0) %>%
select(batsman,runs)
ballsPlayed<- summarise(group_by(ballsPlayed,batsman),count=n())
names(ballsPlayed) <- c("batsman","ballsPlayed")
details <- full_join(details,ballsPlayed,by="batsman")
cat("Total=",sum(details$runs),"\n")
# If there are NAs then
if(sum(is.na(details$fours)) != 0){
details[is.na(details$fours),]$fours <- 0
}
if(sum(is.na(details$sixes)) != 0){
details[is.na(details$sixes),]$sixes <- 0
}
# Out the details
details <- select(details,batsman,ballsPlayed,fours,sixes,runs)
details
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBattingScorecardMatch.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 23 Mar 2016
# Function: teamBattingBattingScorecardOppnAllMatches
# This function computes the batting scorecard for the team against an oppositon
# in all matches against the opposition
#
#
###########################################################################################
#' @title
#' Team batting scorecard of a team in all matches against an opposition
#'
#' @description
#' This function computes returns the batting scorecard (runs, fours, sixes, balls played) for the
#' team in all matches against an opposition
#'
#' @usage
#' teamBattingScorecardOppnAllMatches(matches,main,opposition)
#'
#' @param matches
#' the data frame of all matches between a team and an opposition obtained with
#' the call getAllMatchesBetweenteam()
#'
#' @param main
#' The main team for which scorecard required
#'
#' @param opposition
#' The opposition team
#'
#' @return scorecard
#' The scorecard of all the matches
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get all matches between India and Australia
#' matches <- getAllMatchesBetweenTeams("India","Australia",dir="../data",save=TRUE)
#' # Compute the scorecard of India in matches with australia
#' teamBattingScorecardOppnAllMatches(matches,main="India",opposition="Australia")
#'
#' #Get all matches between Australia and India
#' matches <- getAllMatchesBetweenTeams("Australia","India",dir="../data")
#' #Compute the batting scorecard of Australia
#' teamBattingScorecardOppnAllMatches(matches,"Australia","India")
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatches}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#'
#' @export
#'
teamBattingScorecardOppnAllMatches <- function(matches,main,opposition){
team=batsman=runs=fours=sixes=NULL
byes=legbyes=noballs=wides=NULL
a <-filter(matches,team==main)
b <- select(a,batsman,runs)
names(b) <-c("batsman","runs")
#Compute the number of 4s
c <-
b %>%
mutate(fours=(runs>=4 & runs <6)) %>%
filter(fours==TRUE)
# Group by batsman. Count 4s
d <- summarise(group_by(c, batsman),fours=n())
# Get the total runs for each batsman
e <-summarise(group_by(a,batsman),sum(runs))
names(b) <-c("batsman","runs")
details <- full_join(e,d,by="batsman")
names(details) <-c("batsman","runs","fours")
# Compute sixes
f <-
b %>%
mutate(sixes=(runs ==6)) %>%
filter(sixes == TRUE)
# Group by batsman. COunt 6s
g <- summarise(group_by(f, batsman),sixes=n())
names(g) <-c("batsman","sixes")
#Full join with 4s and 6s
details <- full_join(details,g,by="batsman")
# Count the balls played by the batsman
ballsPlayed <-
a %>%
select(batsman,byes,legbyes,wides,noballs,runs) %>%
filter(wides ==0,noballs ==0,byes ==0,legbyes == 0) %>%
select(batsman,runs)
ballsPlayed<- summarise(group_by(ballsPlayed,batsman),count=n())
names(ballsPlayed) <- c("batsman","ballsPlayed")
details <- full_join(details,ballsPlayed,by="batsman")
cat("Total=",sum(details$runs),"\n")
details <- arrange(details,desc(runs),desc(sixes),desc(fours))
details <- select(details,batsman,ballsPlayed,fours,sixes,runs)
details
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBattingScoredcardOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 25 Mar 2016
# Function: teamBowlersVsBatsmenAllOppnAllMatchesMain
# This function computes the performance of bowlers of team against all opposition in all matches
# This function returns a dataframe
#
###########################################################################################
#' @title
#' Compute team bowlers vs batsmen all opposition all matches
#'
#' @description
#' This function computes performance of bowlers of a team against all opposition in all matches
#'
#' @usage
#' teamBowlersVsBatsmenAllOppnAllMatchesMain(matches,theTeam,rank=0)
#'
#' @param matches
#' the data frame of all matches between a team and aall opposition and all obtained with
#' the call getAllMatchesAllOpposition()
#'
#' @param theTeam
#' The team against which the performance is requires
#'
#' @param rank
#' When the rank is 0 then the performance of all the bowlers is displayed. If rank=n (1,2,3 ..) then
#' the performance of that bowler is given
#'
#' @return dataframe
#' The dataframe with all performances
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get all matches between India and all oppostions
#' matches <-getAllMatchesAllOpposition("India",dir="../data/",save=TRUE)
#'
#' # You could also load directly from the saved file
#' #load("allMatchesAllOpposition-India.RData")
#' # The call below gives the best bowlers of India
#' teamBowlersVsBatsmenAllOppnAllMatchesMain(matches,theTeam="India",rank=0)
#'
#' # The call with rank=1 gives the performance of the 'India' bowler with rank=1
#' teamBowlersVsBatsmenAllOppnAllMatchesMain(matches,theTeam="India",rank=1)
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatches}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesRept}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamBowlersVsBatsmenAllOppnAllMatchesMain <- function(matches,theTeam,rank=0) {
team=bowler=batsman=NULL
runs=over=runsConceded=NULL
a <-filter(matches,team !=theTeam)
b <-summarise(group_by(a,bowler,batsman),sum(runs))
names(b) <- c("bowler","batsman","runsConceded")
# Compute total runs conceded
c <- summarise(group_by(b,bowler),runs=sum(runsConceded))
# Sort by descneding
d <- arrange(c,desc(runs))
# Initialise to NULL
f <- NULL
if(rank == 0){
f <- head(d,10)
} else { # display dispRows for selected bowler with rank
# Pick the chosen bowler
bwlr <- d[rank,]
f <- filter(b,bowler==bwlr$bowler)
f <- arrange(f,desc(runsConceded))
}
f
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBowlersVsBatsmenAllOppnAllMatchesMain.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 25 Mar 2016
# Function: teamBowlersVsBatsmenAllOppnAllMatchesPlot
# This function computes the performance of bowlers against batsman of opposition
#
###########################################################################################
#' @title
#' Plot bowlers vs batsmen against all opposition all matches
#'
#' @description
#' This function computes performance of bowlers of a team against all opposition in all matches
#'
#' @usage
#' teamBowlersVsBatsmenAllOppnAllMatchesPlot(bowlerDF,t1,t2,plot=1)
#'
#' @param bowlerDF
#' The data frame of the bowler whose performance is required
#'
#' @param t1
#' The team against to which the player belong
#'
#' @param t2
#' The opposing team
#'
#' @param plot
#' plot=1 (static),plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get all matches between India and all oppostions
#' matches <-getAllMatchesAllOpposition("India",dir="../data/",save=TRUE)
#'
#' #Get the details of the bowler with the specified rank as a dataframe
#' df <- teamBowlersVsBatsmenAllOppnAllMatchesRept(matches,theTeam="India",rank=1)
#' #Plot this
#' teamBowlersVsBatsmenAllOppnAllMatchesPlot(df,"India","India")
#'
#' df <- teamBowlersVsBatsmenAllOppnAllMatchesRept(matches,theTeam="England",rank=1)
#' teamBowlersVsBatsmenAllOppnAllMatchesPlot(df,"India","England")
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatches}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesMain}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesRept}}\cr
#' @export
#'
teamBowlersVsBatsmenAllOppnAllMatchesPlot <- function(bowlerDF,t1,t2,plot=1){
batsman=runsConceded=team=NULL
ggplotly=NULL
bwlr <- bowlerDF$bowler
if(t2 != "India"){
plot.title <- paste(bwlr,"-Performance against",t2,"batsmen")
print("aa")
}else{
plot.title <- paste(bwlr,"-Performance against all batsmen")
}
if(plot == 1){ #ggplot2
ggplot(data=bowlerDF,aes(x=batsman,y=runsConceded,fill=factor(batsman))) +
facet_grid(. ~ bowler) + geom_bar(stat="identity") +
xlab("Batsman") + ylab("Runs conceded") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),"")))) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
} else if(plot == 2){ #ggplotly
g <- ggplot(data=bowlerDF,aes(x=batsman,y=runsConceded,fill=factor(batsman))) +
facet_grid(. ~ bowler) + geom_bar(stat="identity") +
xlab("Batsman") + ylab("Runs conceded") +
ggtitle(plot.title) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
ggplotly(g,height=500)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBowlersVsBatsmenAllOppnAllMatchesPlot.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 25 Mar 2016
# Function: teamBowlersVsBatsmenAllOppnAllMatchesRept
# This function computes the performance of bowlers of team against all opposition in all matches
# This function returns a dataframe
#
###########################################################################################
#' @title
#' report of Team bowlers vs batsmen against all opposition all matches
#'
#' @description
#' This function computes performance of bowlers of a team against all opposition in all matches
#'
#' @usage
#' teamBowlersVsBatsmenAllOppnAllMatchesRept(matches,theTeam,rank=0)
#'
#' @param matches
#' the data frame of all matches between a team and aall opposition and all obtained with
#' the call getAllMatchesAllOpposition()
#'
#' @param theTeam
#' The team against which the performance is requires
#'
#' @param rank
#' When the rank is 0 then the performance of all the bowlers is displayed. If rank=n (1,2,3 ..) then
#' the performance of that bowler is given
#'
#' @return dataframe
#' The dataframe with all performances
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get all matches between India and all oppostions
#' matches <-getAllMatchesAllOpposition("India",dir="../data/",save=TRUE)
#'
#' # You could also load directly from the saved file
#' #load("allMatchesAllOpposition-India.RData")
#' # The call below gives the best bowlers against India
#' teamBowlersVsBatsmenAllOppnAllMatchesRept(matches,theTeam="India",rank=0)
#'
#' # The call with rank=1 gives the performace of the bowler with rank
#' teamBowlersVsBatsmenAllOppnAllMatchesRept(matches,theTeam="India",rank=1)
#'
#' # The call below gives the overall performance of India bowlers against South Africa
#' teamBatsmenVsBowlersAllOppnAllMatchesRept(matches,"South Africa",rank=0)
#'
#' # The call below gives the performance of best Indias bowlers against Australia
#' teamBowlersVsBatsmenAllOppnAllMatchesRept(matches,"Australia",rank=1)
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatches}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesMain}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#' @export
#'
teamBowlersVsBatsmenAllOppnAllMatchesRept <- function(matches,theTeam,rank=0) {
batsman=runsConceded=team=runs=bowler=NULL
team=bowler=batsman=NULL
a <-filter(matches,team==theTeam)
b <-summarise(group_by(a,bowler,batsman),sum(runs))
names(b) <- c("bowler","batsman","runsConceded")
# Compute total runs conceded
c <- summarise(group_by(b,bowler),runs=sum(runsConceded))
# Sort by descneding
d <- arrange(c,desc(runs))
# Initialise to NULL
f <- NULL
if(rank == 0){
f <- head(d,10)
} else { # display dispRows for selected bowler with rank
# Pick the chosen bowler
bwlr <- d[rank,]
f <- filter(b,bowler==bwlr$bowler)
f <- arrange(f,desc(runsConceded))
}
f
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBowlersVsBatsmenAllOppnAllMatchesRept.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 22 Mar 2016
# Function: teamBowlersVsBatsmenMatch
# This function computes performance of the team bowlers against the opposition batsmen
#
###########################################################################################
#' @title
#' Team bowlers vs batsmen in a match
#'
#' @description
#' This function computes performance of bowlers of a team against an opposition in a match
#'
#' @usage
#' teamBowlersVsBatsmenMatch(match,theTeam,opposition, plot=1)
#'
#' @param match
#' The data frame of the match. This can be obtained with the call for e.g
#' a <- getMatchDetails("England","Pakistan","2006-09-05",dir="../temp")
#'
#'
#' @param theTeam
#' The team against which the performance is required
#'
#' @param opposition
#' The opposition team
#'
#' @param plot
#' plot=1 (static),plot=2(interactive),plot=3(table)
#'
#' @return None or dataframe
#' If plot=TRUE there is no return. If plot=TRUE then the dataframe is returned
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get the match between England and Pakistan
#' a <- getMatchDetails("England","Pakistan","2006-09-05",dir="../temp")
#' teamBowlersVsBatsmenMatch(a,"Pakistan","England")
#' teamBowlersVsBatsmenMatch(a,"England","Pakistan")
#' m <- teamBowlersVsBatsmenMatch(a,"Pakistan","England")
#' }
#'
#'
#' @seealso
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatches}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesRept}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamBowlersVsBatsmenMatch <- function(match,theTeam,opposition, plot=1){
batsman=runsConceded=team=runs=bowler=NULL
ggplotly=NULL
bowler=batsman=NULL
c <- filter(match,team !=theTeam)
b <-summarise(group_by(c,bowler,batsman),sum(runs))
names(b) <- c("bowler","batsman","runsConceded")
# Output plot or dataframe
if(plot == 1){ #ggplot2
plot.title <- paste(theTeam,"Bowler vs Batsman (against",opposition,")")
p <- ggplot(data=b,aes(x=batsman,y=runsConceded,fill=factor(batsman))) +
facet_grid(. ~ bowler) + geom_bar(stat="identity") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),"")))) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
theme(plot.title = element_text(size=14, face="bold.italic",margin=margin(10)))
p
} else if(plot == 2){ #ggplotly
plot.title <- paste(theTeam,"Bowler vs Batsman (against",opposition,")")
p <- ggplot(data=b,aes(x=batsman,y=runsConceded,fill=factor(batsman))) +
facet_grid(. ~ bowler) + geom_bar(stat="identity") +
ggtitle(plot.title) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
theme(plot.title = element_text(size=14, face="bold.italic",margin=margin(10)))
ggplotly(p)
}
else{
b
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBowlersVsBatsmenMatch.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 23 Mar 2016
# Function: teamBowlersVsBatsmenOppnAllMatches
# This function computes the performance of the bowlers and the runs conceded and the batsman
# who scored most
#
#
###########################################################################################
#' @title
#' Team bowlers vs batsmen against an opposition in all matches
#'
#' @description
#' This function computes performance of bowlers of a team against an opposition in all matches
#' against the opposition
#'
#' @usage
#' teamBowlersVsBatsmenOppnAllMatches(matches,main,opposition,plot=1,top=5)
#'
#' @param matches
#' The data frame of all matches between a team the opposition. This dataframe can be obtained with
#' matches <- getAllMatchesBetweenTeams("Australia","India",dir="../data")
#'
#' @param main
#' The main team against which the performance is requires
#'
#' @param opposition
#' The opposition team against which the performance is require
#'
#' @param plot
#' plot=1 (static),plot=2(interactive),plot=3(table)
#'
#' @param top
#' The number of rows to be returned. 5 by default
#'
#' @return dataframe
#' The dataframe with all performances
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get all matches between India and Australia
#' matches <- getAllMatchesBetweenTeams("Australia","India",dir="../data")
#'
#' # Plot the performance of top 5 Indian bowlers against Australia
#' teamBowlersVsBatsmanOppnAllMatches(matches,'India',"Australia",top=5)
#'
#' # Plot the performance of top 3 Australian bowlers against India
#' teamBowlersVsBatsmenOppnAllMatches(matches,"Australia","India",top=3)
#'
#' # Get the top 5 bowlers of Australia. Do not plot but get as a dataframe
#' teamBowlersVsBatsmenOppnAllMatches(matches,"Australia","India",plot=FALSE)
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatches}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesRept}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamBowlersVsBatsmenOppnAllMatches <- function(matches,main,opposition,plot=1,top=5){
noBalls=wides=team=runs=bowler=wicketKind=wicketPlayerOut=NULL
ggplotly=NULL
team=bowler=ball=wides=noballs=runsConceded=overs=batsman=NULL
a <-filter(matches,team != main)
b <-summarise(group_by(a,bowler,batsman),sum(runs))
names(b) <- c("bowler","batsman","runsConceded")
# Compute total runs conceded
c <- summarise(group_by(b,bowler),runs=sum(runsConceded))
# Sort by descneding
d <- arrange(c,desc(runs))
# Pick 5 highest run givers
d <- head(d,top)
bowlers <- as.character(d$bowler)
e <- NULL
for(i in 1:length(bowlers)){
f <- filter(b,bowler==bowlers[i])
e <- rbind(e,f)
}
names(e) <- c("bowler","batsman","runsConceded")
if(plot == 1){ #ggplot2
plot.title = paste("Bowlers vs batsmen -",main," Vs ",opposition,"(all matches)",sep="")
ggplot(data=e,aes(x=batsman,y=runsConceded,fill=factor(batsman))) +
facet_grid(. ~ bowler) + geom_bar(stat="identity") +
#facet_wrap( ~ bowler,scales = "free", ncol=3,drop=TRUE) + #Does not work.Check!
xlab("Batsman") + ylab("Runs conceded") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),"")))) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
} else if(plot == 2){ #ggplotly
plot.title = paste("Bowlers vs batsmen -",main," Vs ",opposition,"(all matches)",sep="")
g <- ggplot(data=e,aes(x=batsman,y=runsConceded,fill=factor(batsman))) +
facet_grid(. ~ bowler) + geom_bar(stat="identity") +
#facet_wrap( ~ bowler,scales = "free", ncol=3,drop=TRUE) + #Does not work.Check!
xlab("Batsman") + ylab("Runs conceded") +
ggtitle(plot.title) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
ggplotly(g,height=500)
} else{
e
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBowlersVsBatsmenOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 24 Mar 2016
# Function: teamBowlersWicketKindOppnAllMatches
# This function computes the the types of wickets taken by the bowlers, caught,bowled, c&b etc
#
#
###########################################################################################
#' @title
#' Team bowlers wicket kind against an opposition in all matches
#'
#' @description
#' This function computes performance of bowlers of a team and the wicket kind against an
#' opposition in all matches against the opposition
#'
#' @usage
#' teamBowlersWicketKindOppnAllMatches(matches,main,opposition,plot=1)
#'
#' @param matches
#' The data frame of all matches between a team the opposition. This dataframe can be obtained with
#' matches <- getAllMatchesBetweenTeams("Australia","India",dir="../data")
#'
#' @param main
#' The team for which the performance is required
#'
#' @param opposition
#' The opposing team
#'
#' @param plot
#' #' @param plot
#' plot=1 (static),plot=2(interactive),plot=3(table)
#'
#' @return None or dataframe
#' The return depends on the value of the plot
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get all matches between India and Australia
#' matches <- getAllMatchesBetweenTeams("Australia","India",dir="../data")
#'
#' teamBowlersWicketKindOppnAllMatches(matches,"India","Australia",plot=TRUE)
#' m <- teamBowlersWicketKindOppnAllMatches(matches,"Australia","India",plot=FALSE)
#'
#' teamBowlersWicketKindOppnAllMatches(matches,"Australia","India",plot=TRUE)
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatches}}
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesRept}}
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}
#'
#' @export
#'
teamBowlersWicketKindOppnAllMatches <- function(matches,main,opposition,plot=1){
team=bowler=ball=NULL
ggplotly=NULL
runs=over=runsConceded=NULL
byes=legbyes=noballs=wides=runConceded=NULL
extras=wicketFielder=wicketKind=wicketPlayerOut=NULL
# Compute the maidens,runs conceded and overs for the bowlers
a <-filter(matches,team !=main)
# only wides and noballs need to be included with runs for bowlers.
# Note: byes and legbyes should not be included
b <- a %>%
select(bowler,ball,noballs,wides,runs,wicketKind,wicketPlayerOut) %>%
mutate(over=gsub("1st\\.","",ball)) %>%
mutate(over=gsub("\\.\\d+","",over))
#Calculate the number of maiden overs
c <- summarise(group_by(b,bowler,over),sum(runs,wides,noballs))
names(c) <- c("bowler","over","runsConceded")
d <-summarize(group_by(c,bowler),maidens=sum(runsConceded==0))
#Compute total runs conceded (runs_wides+noballs)
e <- summarize(group_by(c,bowler),runs=sum(runsConceded))
#Compute number of wickets
h <- b %>%
select(bowler,wicketKind,wicketPlayerOut) %>%
filter(wicketPlayerOut != "nobody")
i <- summarise(group_by(h,bowler),wickets=length(unique(wicketPlayerOut)))
r <- full_join(h,e,by="bowler")
# Set NAs to 0
if(sum(is.na(r$wicketKind)) != 0){
r[is.na(r$wicketKind),]$wicketKind="noWicket"
}
if(sum(is.na(r$wicketPlayerOut)) !=0){
r[is.na(r$wicketPlayerOut),]$wicketPlayerOut="noWicket"
}
if(plot == 1){ #ggplot2
plot.title = paste("Wicket kind taken by bowlers -",main," Vs ",opposition,"(all matches)",sep="")
ggplot(data=r,aes(x=wicketKind,y=runs,fill=factor(wicketKind))) +
facet_wrap( ~ bowler,scales = "fixed", ncol=8) +
geom_bar(stat="identity") +
xlab("Wicket kind") + ylab("Runs conceded") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),"")))) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
} else if(plot == 2){ #ggplotly
plot.title = paste("Wicket kind taken by bowlers -",main," Vs ",opposition,"(all matches)",sep="")
g <- ggplot(data=r,aes(x=wicketKind,y=runs,fill=factor(wicketKind))) +
facet_wrap( ~ bowler,scales = "fixed", ncol=8) +
geom_bar(stat="identity") +
xlab("Wicket kind") + ylab("Runs conceded") +
ggtitle(plot.title) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
ggplotly(g,height=500)
}
else{
r
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBowlersWicketKindOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 24 Mar 2016
# Function: teamBowlersWicketRunsOppnAllMatches
# This function computes the number of wickets taken and runs conceded by the bowlers in
# all matches against the opposition
#
#
###########################################################################################
#' @title
#' Team bowlers wicket runs against an opposition in all matches
#'
#' @description
#' This function computes performance of bowlers of a team and the runs conceded against an
#' opposition in all matches against the opposition
#'
#' @usage
#' teamBowlersWicketRunsOppnAllMatches(matches,main,opposition,plot=1)
#'
#' @param matches
#' The data frame of all matches between a team the opposition. This dataframe can be obtained with
#' matches <- getAllMatchesBetweenTeams("Australia","India",dir="../data")
#'
#' @param main
#' The team for which the performance is required
#'
#' @param opposition
#' The opposing team
#'
#' @param plot
#' plot=1 (static),plot=2(interactive),plot=3(table)
#'
#' @return None or dataframe
#' The return depends on the value of the plot
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get all matches between India and Australia
#' matches <- getAllMatchesBetweenTeams("Australia","India",dir="../data")
#'
#' teamBowlersWicketRunsOppnAllMatches(matches,"India","Australia")
#' m <-teamBowlerWicketsRunsOppnAllMatches(matches,"Australia","India",plot=FALSE)
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatches}}\cr
#' \code{\link{teamBowlersWicketsOppnAllMatches}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesRept}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamBowlersWicketRunsOppnAllMatches <- function(matches,main,opposition,plot=1){
team=bowler=ball=NULL
ggplotly=NULL
runs=over=wickets=NULL
byes=legbyes=noballs=wides=runsConceded=NULL
extras=wicketFielder=wicketKind=wicketPlayerOut=NULL
# Compute the maidens,runs conceded and overs for the bowlers
a <-filter(matches,team !=main)
# only wides and noballs need to be included with runs for bowlers.
# Note: byes and legbyes should not be included
b <- a %>%
select(bowler,ball,noballs,wides,runs,wicketKind,wicketPlayerOut) %>%
mutate(over=gsub("1st\\.","",ball)) %>%
mutate(over=gsub("\\.\\d+","",over))
#Calculate the number of maiden overs
c <- summarise(group_by(b,bowler,over),sum(runs,wides,noballs))
names(c) <- c("bowler","over","runsConceded")
d <-summarize(group_by(c,bowler),maidens=sum(runsConceded==0))
#Compute total runs conceded (runs_wides+noballs)
e <- summarize(group_by(c,bowler),runs=sum(runsConceded))
# Calculate the number of overs bowled by each bwler
f <- select(c,bowler,over)
g <- summarise(group_by(f,bowler),overs=length(unique(over)))
#Compute number of wickets
h <- b %>%
select(bowler,wicketKind,wicketPlayerOut) %>%
filter(wicketPlayerOut != "nobody")
i <- summarise(group_by(h,bowler),wickets=length(unique(wicketPlayerOut)))
#Join the over & maidens
j <- full_join(g,d,by="bowler")
# Add runs
k <- full_join(j,e,by="bowler")
# Add wickets
l <- full_join(k,i,by="bowler")
# Set NAs to 0
if(sum(is.na(l$wickets)) != 0){
l[is.na(l$wickets),]$wickets=0
}
if(plot == 1){ #ggplot2
plot.title = paste("Wicket taken cs Runs conceded -",main," Vs ",opposition,"(all matches)",sep="")
ggplot(data=l,aes(x=factor(wickets),y=runs,fill=factor(wickets))) +
facet_wrap( ~ bowler,scales = "fixed", ncol=8) +
geom_bar(stat="identity") +
xlab("Number of wickets") + ylab('Runs conceded') +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),"")))) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
} else if(plot == 2){ #ggplotly
plot.title = paste("Wicket taken cs Runs conceded -",main," Vs ",opposition,"(all matches)",sep="")
g <- ggplot(data=l,aes(x=factor(wickets),y=runs,fill=factor(wickets))) +
facet_wrap( ~ bowler,scales = "fixed", ncol=8) +
geom_bar(stat="identity") +
xlab("Number of wickets") + ylab('Runs conceded') +
ggtitle(plot.title) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
ggplotly(g,height=500)
} else {
l
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBowlersWicketRunsOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 23 Mar 2016
# Function: teamBowlersWicketsOppnAllMatches
# This function computes the total wickets taken by the top 20(default) bowlers against the
# opposition
#
#
###########################################################################################
#' @title
#' Team bowlers wickets against an opposition in all matches
#'
#' @description
#' This function computes performance of bowlers of a team and the wickets taken against an
#' opposition in all matches against the opposition
#'
#' @usage
#' teamBowlersWicketsOppnAllMatches(matches,main,opposition,plot=1,top=20)
#'
#' @param matches
#' The data frame of all matches between a team the opposition. This dataframe can be obtained with
#' matches <- getAllMatchesBetweenTeams("Australia","India",dir="../data")
#'
#' @param main
#' The team for which the performance is required
#'
#' @param opposition
#' The opposing team
#'
#' @param plot
#' plot=1 (static),plot=2(interactive),plot=3(table)
#'
#' @param top
#' The number of top bowlers to be included in the result
#'
#' @return None or dataframe
#' The return depends on the value of the plot
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get all matches between India and Australia
#' matches <- getAllMatchesBetweenTeams("Australia","India",dir="../data")
#'
#' #Display top 20
#' teamBowlersWicketsOppnAllMatches(matches,"India","Australia")
#' #Display and plot top 10
#' teamBowlersWicketsOppnAllMatches(matches,"Australia","India",top=10)
#'
#' #Do not plot but return as dataframe
#' teamBowlersWicketsOppnAllMatches(matches,"India","Australia",plot=FALSE)
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatches}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesRept}}\cr
#' \code{\link{teamBowlersWicketRunsOppnAllMatches}}\cr
#'
#' @export
#'
teamBowlersWicketsOppnAllMatches <- function(matches,main,opposition,plot=1,top=20){
team=bowler=ball=noballs=runs=NULL
ggplotly=NULL
wicketKind=wicketPlayerOut=over=wickets=NULL
batsman=wides=NULL
a = NULL
#Filter the matches by the team
a <-filter(matches,team!=main)
# only wides and noballs need to be included with runs for bowlers.
# Note: byes and legbyes should not be included
b <- a %>%
select(bowler,ball,noballs,wides,runs,wicketKind,wicketPlayerOut) %>%
mutate(over=gsub("1st\\.","",ball)) %>%
mutate(over=gsub("\\.\\d+","",over))
#Compute number of wickets
c <- b %>%
select(bowler,wicketKind,wicketPlayerOut) %>%
filter(wicketPlayerOut != "nobody")
d <- summarise(group_by(c,bowler),wickets=length(unique(wicketPlayerOut)))
e <- arrange(d,desc(wickets))
# Display maximum or the requested 'top' size
sz <- dim(e)
if(sz[1] > top){
e <- e[1:top,]
}else{
e <- e[1:sz[1],]
}
names(e) <- c("bowler","wickets")
if(plot == 1){ #ggplot2
plot.title = paste(main," Bowler performances ","(against ",opposition," all matches)",sep="")
ggplot(data=e,aes(x=bowler,y=wickets,fill=factor(bowler))) +
geom_bar(stat="identity") +
#facet_wrap( ~ bowler,scales = "free", ncol=3,drop=TRUE) + #Does not work.Check!
xlab("Batsman") + ylab("Wickets taken") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),"")))) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
} else if(plot == 2){ #ggplotly
plot.title = paste(main," Bowler performances ","(against ",opposition," all matches)",sep="")
g <- ggplot(data=e,aes(x=bowler,y=wickets,fill=factor(bowler))) +
geom_bar(stat="identity") +
#facet_wrap( ~ bowler,scales = "free", ncol=3,drop=TRUE) + #Does not work.Check!
xlab("Batsman") + ylab("Wickets taken") +
ggtitle(plot.title) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
ggplotly(g,500)
} else{
e
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBowlersWicketsOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 26 Mar 2016
# Function: teamBowlingPerfDetails
# This function uses gets the bowling performance of a team
#
###########################################################################################
#' @title
#' get team bowling performance details
#'
#' @description
#' This function computes performance of bowlers of a team a
#'
#' @usage
#' teamBowlingPerfDetails(match,theTeam,includeInfo=FALSE)
#'
#' @param match
#' The data frame of all match
#'
#' @param theTeam
#' The team for which the performance is required
#'
#' @param includeInfo
#' If true details like venie,winner, result etc are included
#'
#' @return dataframe
#' The dataframe of bowling performance
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get all matches between India and Australia
#' match <- getMatchDetails("England","Pakistan","2006-09-05",dir="../temp")
#' teamBowlingPerf(match,"India",includeInfo=TRUE)
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatches}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesRept}}\cr
#' \code{\link{teamBowlersWicketRunsOppnAllMatches}}\cr
#'
#' @export
#'
teamBowlingPerfDetails <- function(match,theTeam,includeInfo=FALSE){
noBalls=wides=team=runs=bowler=wicketKind=wicketPlayerOut=NULL
team=bowler=ball=wides=noballs=runsConceded=overs=over=NULL
# Initialise to NULL
l <- NULL
a <-filter(match,team!=theTeam)
sz <- dim(a)
if(sz[1] == 0){
#cat("No bowling records.\n")
return(NULL)
}
a1 <- unlist(strsplit(a$ball[1],"\\."))
# Create a string for substitution 1st or 2nd
a2 <- paste(a1[1],"\\.",sep="")
# only wides and noballs need to be included with runs for bowlers.
# Note: byes and legbyes should not be included
b <- a %>%
select(bowler,ball,noballs,wides,runs,wicketKind,wicketPlayerOut) %>%
#mutate(over=gsub("1st\\.","",ball)) %>%
mutate(over=gsub(a2,"",ball)) %>%
mutate(over=gsub("\\.\\d+","",over))
#Calculate the number of maiden overs
c <- summarise(group_by(b,bowler,over),sum(runs,wides,noballs))
names(c) <- c("bowler","over","runsConceded")
d <-summarize(group_by(c,bowler),maidens=sum(runsConceded==0))
#Compute total runs conceded (runs_wides+noballs)
e <- summarize(group_by(c,bowler),runs=sum(runsConceded))
# Calculate the number of overs bowled by each bwler
f <- select(c,bowler,over)
g <- summarise(group_by(f,bowler),overs=length(unique(over)))
#Compute number of wickets
h <- b %>%
select(bowler,wicketKind,wicketPlayerOut) %>%
filter(wicketPlayerOut != "nobody")
#i <- summarise(group_by(h,bowler),wickets=length(unique(wicketPlayerOut)))
#Join the over & maidens
j <- full_join(g,d,by="bowler")
# Add runs
k <- full_join(j,e,by="bowler")
# Add wickets
l <- full_join(k,h,by="bowler")
# Remove unnecessary factors
l$wicketPlayerOut <-factor(l$wicketPlayerOut)
l$wicketKind <- factor(l$wicketKind)
# Set as character to assign values
l$wicketPlayerOut <- as.character(l$wicketPlayerOut)
l$wicketKind <- as.character(l$wicketKind)
# Set NAs to none
if(sum(is.na(l$wicketKind)) != 0){
l[is.na(l$wicketKind),]$wicketKind <-"none"
}
if(sum(is.na(l$wicketPlayerOut)) != 0){
l[is.na(l$wicketPlayerOut),]$wicketPlayerOut="nobody"
}
l
#Calculate strike rate
l <- mutate(l,economyRate=round(((runs/overs)),2))
# Determine the opposition
t <- match$team != theTeam
# Pick the 1st element
t1 <- match$team[t]
opposition <- as.character(t1[1])
if(includeInfo == TRUE) {
l$date <- a$date[1]
l$venue <- a$venue[1]
l$opposition <- opposition
l$winner <- a$winner[1]
l$result <- a$result[1]
}
l
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBowlingPerfDetails.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 23 Mar 2016
# Function: teamBowlingPerfOppnAllMatches
# This function computes the team bowling performance against an opposition and picks
# the top bowlers based on number of wickets taken
#
#
###########################################################################################
#' @title
#' team bowling performance all matches against an opposition
#'
#' @description
#' This function computes returns the bowling dataframe of bowlers deliveries, maidens, overs, wickets
#' against an opposition in all matches
#'
#' @usage
#' teamBowlingPerfOppnAllMatches(matches,main,opposition)
#'
#' @param matches
#' The matches of the team against an opposition.
#'
#' @param main
#' Team for which bowling performance is required
#'
#' @param opposition
#' The opposition Team
#'
#'
#' @return l
#' A data frame with the bowling performance
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' #Get all matches between India and Autralia
#' matches <- getAllMatchesBetweenTeams("Australia","India",dir="../data")
#'
#' # Or load directly from saved file
#' # load("India-Australia-allMatches.RData")
#'
#' teamBowlingPerfOppnAllMatches(matches,"India","Australia")
#' teamBowlingPerfOppnAllMatches(matches,main="Australia",opposition="India")
#' }
#'
#' @seealso
#' \code{\link{teamBowlersWicketsOppnAllMatches}}\cr
#' \code{\link{teamBowlersWicketRunsOppnAllMatches}}\cr
#' \code{\link{teamBowlersWicketKindOppnAllMatches}}\cr
#'
#' @export
#'
teamBowlingPerfOppnAllMatches <- function(matches,main,opposition){
noBalls=wides=team=runs=bowler=wicketKind=wicketPlayerOut=NULL
team=bowler=ball=wides=noballs=runsConceded=overs=over=NULL
wickets=maidens=NULL
# Compute the maidens,runs conceded and overs for the bowlers
a <-filter(matches,team != main)
# only wides and noballs need to be included with runs for bowlers.
# Note: byes and legbyes should not be included
b <- a %>%
select(bowler,ball,noballs,wides,runs,wicketKind,wicketPlayerOut) %>%
mutate(over=gsub("1st\\.","",ball)) %>%
mutate(over=gsub("\\.\\d+","",over))
#Calculate the number of maiden overs
c <- summarise(group_by(b,bowler,over),sum(runs,wides,noballs))
names(c) <- c("bowler","over","runsConceded")
d <-summarize(group_by(c,bowler),maidens=sum(runsConceded==0))
#Compute total runs conceded (runs_wides+noballs)
e <- summarize(group_by(c,bowler),runs=sum(runsConceded))
# Calculate the number of overs bowled by each bwler
f <- select(c,bowler,over)
g <- summarise(group_by(f,bowler),overs=length(unique(over)))
#Compute number of wickets
h <- b %>%
select(bowler,wicketKind,wicketPlayerOut) %>%
filter(wicketPlayerOut != "nobody")
i <- summarise(group_by(h,bowler),wickets=length(unique(wicketPlayerOut)))
#Join the over & maidens
j <- full_join(g,d,by="bowler")
# Add runs
k <- full_join(j,e,by="bowler")
# Add wickets
l <- full_join(k,i,by="bowler")
# Set NAs to 0 if there are any
if(sum(is.na(l$wickets)) != 0){
l[is.na(l$wickets),]$wickets=0
}
# Arrange in descending order of wickets and runs and ascending order for maidens
l <-arrange(l,desc(wickets),desc(runs),maidens)
l
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBowlingPerfOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 25 Mar 2016
# Function: teamBowlingScorecardAllOppnAllMatches
# This function computes the performance of bowlers of team against all opposition in all matches
# This function returns a dataframe
#
###########################################################################################
#' @title
#' Team bowling scorecard all opposition all matches
#'
#' @description
#' This function computes returns the bowling dataframe of bowlers deliveries, maidens, overs, wickets
#' against all oppositions in all matches
#'
#' @usage
#' teamBowlingScorecardAllOppnAllMatches(matches,theTeam)
#'
#' @param matches
#' The matches of the team against all oppositions and all matches
#'
#' @param theTeam
#' Team for which bowling performance is required
#'
#'
#' @return l
#' A data frame with the bowling performance in alll matches against all oppositions
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' #Get all matches between India and other opposition
#' matches <-getAllMatchesAllOpposition("India",dir="../data/",save=TRUE)
#'
#' # Or load directly from saved file
#' # load("allMatchesAllOpposition-India.RData")
#'
#' # Top opposition bowlers performances against India
#' teamBowlingScorecardAllOppnAllMatches(matches,"India")
#'
#' #Top Indian bowlers against respective opposition
#' teamBowlingScorecardAllOppnAllMatches(matches,'Australia')
#' teamBowlingScorecardAllOppnAllMatches(matches,'South Africa')
#' teamBowlingScorecardAllOppnAllMatches(matches,'England')
#' }
#'
#' @seealso
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesMain}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamBowlingScorecardAllOppnAllMatches <- function(matches,theTeam){
noBalls=wides=team=runs=bowler=wicketKind=wicketPlayerOut=NULL
team=bowler=ball=wides=noballs=runsConceded=overs=NULL
over=wickets=maidens=NULL
a <-filter(matches,team==theTeam)
a1 <- unlist(strsplit(a$ball[1],"\\."))
# Create a string for substitution 1st or 2nd
a2 <- paste(a1[1],"\\.",sep="")
# only wides and noballs need to be included with runs for bowlers.
# Note: byes and legbyes should not be included
b <- a %>%
select(bowler,ball,noballs,wides,runs,wicketKind,wicketPlayerOut) %>%
#mutate(over=gsub("1st\\.","",ball)) %>%
mutate(over=gsub(a2,"",ball)) %>%
mutate(over=gsub("\\.\\d+","",over))
#Calculate the number of maiden overs
c <- summarise(group_by(b,bowler,over),sum(runs,wides,noballs))
names(c) <- c("bowler","over","runsConceded")
d <-summarize(group_by(c,bowler),maidens=sum(runsConceded==0))
#Compute total runs conceded (runs_wides+noballs)
e <- summarize(group_by(c,bowler),runs=sum(runsConceded))
# Calculate the number of overs bowled by each bwler
f <- select(c,bowler,over)
g <- summarise(group_by(f,bowler),overs=length(unique(over)))
#Compute number of wickets
h <- b %>%
select(bowler,wicketKind,wicketPlayerOut) %>%
filter(wicketPlayerOut != "nobody")
i <- summarise(group_by(h,bowler),wickets=length(wicketPlayerOut))
#Join the over & maidens
j <- full_join(g,d,by="bowler")
# Add runs
k <- full_join(j,e,by="bowler")
# Add wickets
l <- full_join(k,i,by="bowler")
# Set NAs to 0 if there are any
if(sum(is.na(l$wickets)) != 0){
l[is.na(l$wickets),]$wickets=0
}
# Arrange in descending order of wickets and runs and ascending order for maidens
l <-arrange(l,desc(wickets),desc(runs),maidens)
l
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBowlingScorecardAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 25 Mar 2016
# Function: teamBowlingScorecardAllOppnAllMatchesMain
# This function computes the performance of bowlers of team against all opposition in all matches
# This function returns a dataframe
#
###########################################################################################
#' @title
#' Team bowling scorecard all opposition all matches Main
#'
#' @description
#' This function computes returns the bowling dataframe of best bowlers deliveries, maidens, overs, wickets
#' against all oppositions in all matches
#'
#' @usage
#' teamBowlingScorecardAllOppnAllMatchesMain(matches,theTeam)
#'
#' @param matches
#' The matches of the team against all oppositions and all matches
#'
#' @param theTeam
#' Team for which bowling performance is required
#'
#'
#' @return l
#' A data frame with the bowling performance in alll matches against all oppositions
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' #Get all matches between India and other opposition
#' matches <-getAllMatchesAllOpposition("India",dir="../data/",save=TRUE)
#'
#' # Or load directly from saved file
#' # load("allMatchesAllOpposition-India.RData")
#'
#' # Top opposition bowlers of India
#' teamBowlingScorecardAllOppnAllMatchesMain(matches,"India")
#' }
#'
#' @seealso
#' \code{\link{teamBowlingScorecardAllOppnAllMatches}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamBowlingScorecardAllOppnAllMatchesMain <- function(matches,theTeam){
team=bowler=batsman=runs=runsConceded=NULL
ball=noballs=wides=wicketKind=maidens=NULL
wicketPlayerOut=over=wickets=NULL
a <-filter(matches,team!=theTeam)
a1 <- unlist(strsplit(a$ball[1],"\\."))
# Create a string for substitution 1st or 2nd
a2 <- paste(a1[1],"\\.",sep="")
# only wides and noballs need to be included with runs for bowlers.
# Note: byes and legbyes should not be included
b <- a %>%
select(bowler,ball,noballs,wides,runs,wicketKind,wicketPlayerOut) %>%
#mutate(over=gsub("1st\\.","",ball)) %>%
mutate(over=gsub(a2,"",ball)) %>%
mutate(over=gsub("\\.\\d+","",over))
#Calculate the number of maiden overs
c <- summarise(group_by(b,bowler,over),sum(runs,wides,noballs))
names(c) <- c("bowler","over","runsConceded")
d <-summarize(group_by(c,bowler),maidens=sum(runsConceded==0))
#Compute total runs conceded (runs_wides+noballs)
e <- summarize(group_by(c,bowler),runs=sum(runsConceded))
# Calculate the number of overs bowled by each bwler
f <- select(c,bowler,over)
g <- summarise(group_by(f,bowler),overs=length(unique(over)))
#Compute number of wickets
h <- b %>%
select(bowler,wicketKind,wicketPlayerOut) %>%
filter(wicketPlayerOut != "nobody")
i <- summarise(group_by(h,bowler),wickets=length(wicketPlayerOut))
#Join the over & maidens
j <- full_join(g,d,by="bowler")
# Add runs
k <- full_join(j,e,by="bowler")
# Add wickets
l <- full_join(k,i,by="bowler")
# Set NAs to 0 if there are any
if(sum(is.na(l$wickets)) != 0){
l[is.na(l$wickets),]$wickets=0
}
# Arrange in descending order of wickets and runs and ascending order for maidens
l <-arrange(l,desc(wickets),desc(runs),maidens)
l
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBowlingScorecardAllOppnAllMatchesMain.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 21 Mar 2016
# Function: teamBowlingScorecardMatch
# This function computes the performance of bowlers of team in a match.
# This function returns a dataframe
#
###########################################################################################
#' @title
#' Compute and return the bowling scorecard of a team in a match
#'
#' @description
#' This function computes and returns the bowling scorecard of a team in a match
#'
#' @usage
#' teamBowlingScorecardMatch(match,theTeam)
#'
#' @param match
#' The match between the teams
#'
#' @param theTeam
#' Team for which bowling performance is required
#'
#' @return l
#' A data frame with the bowling performance in alll matches against all oppositions
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' #Get all matches between India and other opposition
#' a <- getMatchDetails("England","Pakistan","2006-09-05",dir="../temp")
#'
#' teamBowlingScorecardMatch(a,'England')
#' }
#'
#' @seealso
#' \code{\link{teamBowlingWicketMatch}}\cr
#' \code{\link{teamBowlersVsBatsmenMatch}}\cr
#' \code{\link{teamBattingScorecardMatch}}\cr
#'
#' @export
#'
teamBowlingScorecardMatch <- function(match,theTeam){
noBalls=wides=team=runs=bowler=wicketKind=wicketPlayerOut=NULL
team=bowler=ball=wides=noballs=runsConceded=overs=over=NULL
# Compute the maidens,runs conceded and overs for the bowlers.
# The bowlers performance of the team is got when the other side is batting. Hence '!-"
a <-filter(match,team != theTeam)
a1 <- unlist(strsplit(a$ball[1],"\\."))
# Create a string for substitution 1st or 2nd
a2 <- paste(a1[1],"\\.",sep="")
# only wides and noballs need to be included with runs for bowlers.
# Note: byes and legbyes should not be included
b <- a %>%
select(bowler,ball,noballs,wides,runs,wicketKind,wicketPlayerOut) %>%
#mutate(over=gsub("1st\\.","",ball)) %>%
mutate(over=gsub(a2,"",ball)) %>%
mutate(over=gsub("\\.\\d+","",over))
#Calculate the number of maiden overs
c <- summarise(group_by(b,bowler,over),sum(runs,wides,noballs))
names(c) <- c("bowler","over","runsConceded")
d <-summarize(group_by(c,bowler),maidens=sum(runsConceded==0))
#Compute total runs conceded (runs_wides+noballs)
e <- summarize(group_by(c,bowler),runs=sum(runsConceded))
# Calculate the number of overs bowled by each bwler
f <- select(c,bowler,over)
g <- summarise(group_by(f,bowler),overs=length(unique(over)))
#Compute number of wickets
h <- b %>%
select(bowler,wicketKind,wicketPlayerOut) %>%
filter(wicketPlayerOut != "nobody")
i <- summarise(group_by(h,bowler),wickets=length(unique(wicketPlayerOut)))
#Join the over & maidens
j <- full_join(g,d,by="bowler")
# Add runs
k <- full_join(j,e,by="bowler")
# Add wickets
l <- full_join(k,i,by="bowler")
# Set NAs to 0
if(sum(is.na(l$wickets)) != 0){
l[is.na(l$wickets),]$wickets=0
}
l
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBowlingScorecardMatch.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 25 Mar 2016
# Function: teamBowlingWicketKindAllOppnAllMatches
# This function computes the wicket kind of bowlers against all opposition
#
###########################################################################################
#' @title
#' team bowling wicket kind against all opposition all matches
#'
#' @description
#' This function computes returns kind of wickets (caught, bowled etc) of bowlers in all matches against
#' all oppositions. The user can chose to plot or return a data frame
#'
#' @usage
#' teamBowlingWicketKindAllOppnAllMatches(matches,t1,t2="All",plot=1)
#'
#' @param matches
#' The matches of the team against all oppositions and all matches
#'
#' @param t1
#' Team for which bowling performance is required
#'
#' @param t2
#' t2=All gives the performance of the team against all opponents. Giving a opposing team (Australia, India
#' ) will give the performance against this team
#'
#' @param plot
#' plot=1 (static),plot=2(interactive),plot=3(table)
#'
#' @return None or data fame
#' A data frame with the bowling performance in alll matches against all oppositions
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' #Get all matches between India and other opposition
#' matches <-getAllMatchesAllOpposition("India",dir="../data/",save=TRUE)
#'
#' # Or load directly from saved file
#' # load("allMatchesAllOpposition-India.RData")
#'
#' teamBowlingWicketKindAllOppnAllMatches(matches,t1="India",t2="All")
#' m <-teamBowlingWicketKindAllOppnAllMatches(matches,t1="India",t2="All",plot=FALSE)
#'
#' teamBowlingWicketKindAllOppnAllMatches(matches,t1="India",t2="Bangladesh")
#' teamBowlingWicketKindAllOppnAllMatches(matches,t1="India",t2="South Africa")
#' }
#'
#' @seealso
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesMain}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamBowlingWicketKindAllOppnAllMatches <- function(matches,t1,t2="All",plot=1){
noBalls=wides=team=runs=bowler=wicketKind=wicketPlayerOut=NULL
ggplotly=NULL
team=bowler=ball=wides=noballs=runsConceded=overs=NULL
over=wickets=NULL
a <- NULL
if(t2 == "All"){
a <-filter(matches,team==t1)
} else {
a <-filter(matches,team==t2)
}
a1 <- unlist(strsplit(a$ball[1],"\\."))
# Create a string for substitution 1st or 2nd
a2 <- paste(a1[1],"\\.",sep="")
# only wides and noballs need to be included with runs for bowlers.
# Note: byes and legbyes should not be included
b <- a %>%
select(bowler,ball,noballs,wides,runs,wicketKind,wicketPlayerOut) %>%
#mutate(over=gsub("1st\\.","",ball)) %>%
mutate(over=gsub(a2,"",ball)) %>%
mutate(over=gsub("\\.\\d+","",over))
#Compute number of wickets (remove nobody)
c <- b %>%
select(bowler,wicketKind,wicketPlayerOut) %>%
filter(wicketPlayerOut != "nobody")
# Count wickets by bowlers
d <- summarise(group_by(c,bowler),wickets=length(wicketPlayerOut))
# Arrange in descending order
e <- arrange(d,desc(wickets))
# Pick the top 8
f <- e[1:8,]
# Create a character vector of top 8 bowlers
g <- as.character(f$bowler)
# Select these top 8
n <- NULL
for(m in 1:8){
mm <- filter(c,bowler==g[m])
n <- rbind(n,mm)
}
# Summarise by the different wicket kinds for each bowler
p <- summarise(group_by(n,bowler,wicketKind),m=n())
if(plot == 1){ #ggplot2
plot.title <- paste(t1,"vs",t2,"wicket-kind of bowlers")
# Plot
ggplot(data=p,aes(x=wicketKind,y=m,fill=factor(wicketKind))) +
facet_wrap( ~ bowler,scales = "fixed", ncol=8) +
geom_bar(stat="identity") +
xlab("Wicket kind") + ylab("Wickets") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),"")))) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
} else if(plot == 2){ #ggplotly
plot.title <- paste(t1,"vs",t2,"wicket-kind of bowlers")
# Plot
g <- ggplot(data=p,aes(x=wicketKind,y=m,fill=factor(wicketKind))) +
facet_wrap( ~ bowler,scales = "fixed", ncol=8) +
geom_bar(stat="identity") +
xlab("Wicket kind") + ylab("Wickets") +
ggtitle(plot.title) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
ggplotly(g,height=500)
}else{
p
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBowlingWicketKindAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 21 Mar 2016
# Function: teamBowlingWicketKindMatch
# This function computes the performance of bowlers of team with the wicketkind (caught, bowled,
# caught & bowled) for the team
#
#
###########################################################################################
#' @title
#' Compute and plot the wicket kinds by bowlers in match
#'
#' @description
#' This function computes returns kind of wickets (caught, bowled etc) of bowlers in a match between 2 teams
#'
#' @usage
#' teamBowlingWicketKindMatch(match,theTeam,opposition,plot=1)
#'
#' @param match
#' The match between the teams
#'
#' @param theTeam
#' Team for which bowling performance is required
#'
#' @param opposition
#' The opposition team
#'
#' @param plot
#' plot=1 (static),plot=2(interactive),plot=3(table)
#'
#' @return None or data fame
#' A data frame with the bowling performance in alll matches against all oppositions
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' #Get the match details
#' a <- getMatchDetails("England","Pakistan","2006-09-05",dir="../temp")
#'
#' teamBowlingWicketKindMatch(a,"England","Pakistan",plot=FALSE)
#' teamBowlingWicketKindMatch(a,"Pakistan","England")
#' }
#'
#' @seealso
#' \code{\link{teamBowlingWicketMatch}}\cr
#' \code{\link{teamBowlingWicketRunsMatch}}\cr
#' \code{\link{teamBowlersVsBatsmenMatch}}\cr
#'
#' @export
#'
teamBowlingWicketKindMatch <- function(match,theTeam,opposition,plot=1){
noBalls=wides=team=runs=bowler=wicketKind=wicketPlayerOut=NULL
ggplotly=NULL
team=bowler=ball=wides=noballs=runsConceded=overs=over=NULL
# The performance of bowlers of the team is got when the other side is batting. Hence '!-"
# Filter the bowler's performance
a <-filter(match,team !=theTeam)
# Compute the maidens,runs conceded and overs for the bowlers
a1 <- unlist(strsplit(a$ball[1],"\\."))
# Create a string for substitution 1st or 2nd
a2 <- paste(a1[1],"\\.",sep="")
# only wides and noballs need to be included with runs for bowlers.
# Note: byes and legbyes should not be included
b <- a %>%
select(bowler,ball,noballs,wides,runs,wicketKind,wicketPlayerOut) %>%
#mutate(over=gsub("1st\\.","",ball)) %>%
mutate(over=gsub(a2,"",ball)) %>%
mutate(over=gsub("\\.\\d+","",over))
#Calculate the number of maiden overs
c <- summarise(group_by(b,bowler,over),sum(runs,wides,noballs))
names(c) <- c("bowler","over","runsConceded")
d <-summarize(group_by(c,bowler),maidens=sum(runsConceded==0))
#Compute total runs conceded (runs_wides+noballs)
e <- summarize(group_by(c,bowler),runs=sum(runsConceded))
#Compute number of wickets
h <- b %>%
select(bowler,wicketKind,wicketPlayerOut) %>%
filter(wicketPlayerOut != "nobody")
i <- summarise(group_by(h,bowler),wickets=length(unique(wicketPlayerOut)))
j <- full_join(h,e,by="bowler")
# Make as.character to assign values
j$wicketKind = as.character(j$wicketKind)
j$wicketPlayerOut = as.character(j$wicketPlayerOut)
# Set NAs to 0
if(sum(is.na(j$wicketKind) !=0)){
j[is.na(j$wicketKind),]$wicketKind="noWicket"
}
if(sum(is.na(j$wicketPlayerOut) != 0)){
j[is.na(j$wicketPlayerOut),]$wicketPlayerOut="noWicket"
}
if(plot == 1){ #ggplot2
plot.title <- paste(theTeam,"Wicketkind vs Runs given (against",opposition,")")
p <- ggplot(data=j,aes(x=wicketKind,y=runs,fill=factor(wicketKind))) +
facet_grid(. ~ bowler,scales = "free_x", space = "free_x") +
geom_bar(stat="identity") +
xlab("Wicket kind") + ylab("Total runs conceded") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),"")))) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
theme(plot.title = element_text(size=14,margin=margin(10)))
p
} else if(plot == 2){ #ggplotly
plot.title <- paste(theTeam,"Wicketkind vs Runs given (against",opposition,")")
p <- ggplot(data=j,aes(x=wicketKind,y=runs,fill=factor(wicketKind))) +
facet_grid(. ~ bowler,scales = "free_x", space = "free_x") +
geom_bar(stat="identity") +
xlab("Wicket kind") + ylab("Total runs conceded") +
ggtitle(plot.title) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
theme(plot.title = element_text(size=14,margin=margin(10)))
ggplotly(p)
}
else{
j
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBowlingWicketKindMatch.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 21 Mar 2016
# Function: teamBowlingWicketMatch
# This function computes the performance of bowlers and the wickets taken
# The user has a choice of either taking the output as a plot or as a dataframe
#
###########################################################################################
#' @title
#' Compute and plot wickets by bowlers in match
#'
#' @description
#' This function computes returns the wickets taken bowlers in a match between 2 teams
#'
#' @usage
#' teamBowlingWicketMatch(match,theTeam,opposition, plot=1)
#'
#' @param match
#' The match between the teams
#'
#' @param theTeam
#' Team for which bowling performance is required
#'
#' @param opposition
#' The opposition team
#'
#' @param plot
#' plot=1 (static),plot=2(interactive), plot=3 (table)
#'
#' @return None or data fame
#' A data frame with the bowling performance in alll matches against all oppositions
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' #Get the match details
#' a <- getMatchDetails("England","Pakistan","2006-09-05",dir="../temp")
#'
#' teamBowlingWicketMatch(a,"England","Pakistan",plot=FALSE)
#' teamBowlingWicketMatch(a,"Pakistan","England")
#' }
#'
#' @seealso
#' \code{\link{teamBowlingWicketMatch}}\cr
#' \code{\link{teamBowlingWicketRunsMatch}}\cr
#' \code{\link{teamBowlersVsBatsmenMatch}}\cr
#'
#' @export
#'
teamBowlingWicketMatch <- function(match,theTeam,opposition,plot=1){
noBalls=wides=team=runs=bowler=wicketKind=wicketPlayerOut=NULL
ggplotly=NULL
team=bowler=ball=wides=noballs=runsConceded=overs=over=NULL
# The bowlers performance of the team is got when the other side is batting. Hence '!-"
# Filter the data frame
a <-filter(match,team!=theTeam)
# Compute the maidens,runs conceded and overs for the bowlers
a1 <- unlist(strsplit(a$ball[1],"\\."))
# Create a string for substitution 1st or 2nd
a2 <- paste(a1[1],"\\.",sep="")
# only wides and noballs need to be included with runs for bowlers.
# Note: byes and legbyes should not be included
b <- a %>%
select(bowler,ball,noballs,wides,runs,wicketKind,wicketPlayerOut) %>%
#mutate(over=gsub("1st\\.","",ball)) %>%
mutate(over=gsub(a2,"",ball)) %>%
mutate(over=gsub("\\.\\d+","",over))
#Calculate the number of maiden overs
c <- summarise(group_by(b,bowler,over),sum(runs,wides,noballs))
names(c) <- c("bowler","over","runsConceded")
d <-summarize(group_by(c,bowler),maidens=sum(runsConceded==0))
#Compute total runs conceded (runs_wides+noballs)
e <- summarize(group_by(c,bowler),runs=sum(runsConceded))
#Compute number of wickets
h <- b %>%
select(bowler,wicketKind,wicketPlayerOut) %>%
filter(wicketPlayerOut != "nobody")
i <- summarise(group_by(h,bowler),wickets=length(unique(wicketPlayerOut)))
j <- full_join(h,e,by="bowler")
# Make as.character to assign values
j$wicketKind = as.character(j$wicketKind)
j$wicketPlayerOut = as.character(j$wicketPlayerOut)
# Set NAs to 0
if(sum(is.na(j$wicketKind) !=0)){
j[is.na(j$wicketKind),]$wicketKind="noWicket"
}
if(sum(is.na(j$wicketPlayerOut) != 0)){
j[is.na(j$wicketPlayerOut),]$wicketPlayerOut="noWicket"
}
if(plot == 1){ #ggplot2
plot.title <- paste(theTeam,"No of Wickets vs Runs conceded (against",opposition,")")
p <-ggplot(data=j,aes(x=wicketPlayerOut,y=runs,fill=factor(wicketPlayerOut))) +
facet_grid(. ~ bowler,scales = "free_x", space = "free_x") +
geom_bar(stat="identity") +
xlab("Batsman out") + ylab("Total runs conceded") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),"")))) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
theme(plot.title = element_text(size=14,margin=margin(10)))
p
} else if(plot == 2){ #ggplotly
plot.title <- paste(theTeam,"No of Wickets vs Runs conceded (against",opposition,")")
p <-ggplot(data=j,aes(x=wicketPlayerOut,y=runs,fill=factor(wicketPlayerOut))) +
facet_grid(. ~ bowler,scales = "free_x", space = "free_x") +
geom_bar(stat="identity") +
xlab("Batsman out") + ylab("Total runs conceded") +
ggtitle(plot.title) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
theme(plot.title = element_text(size=14,margin=margin(10)))
ggplotly(p)
}
else{
j
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBowlingWicketMatch.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 25 Mar 2016
# Function: teamBowlingWicketRunsAllOppnAllMatches
# This function computes the wickets taken and the runs conceded against all opposition
#
###########################################################################################
#' @title
#' Team bowling wicket runs all matches against all oppositions
#'
#' @description
#' This function computes the number of wickets and runs conceded by bowlers in all matches against
#' all oppositions. The user can chose to plot or return a data frame
#'
#' @usage
#' teamBowlingWicketRunsAllOppnAllMatches(matches,t1,t2="All",plot=1)
#'
#' @param matches
#' The matches of the team against all oppositions and all matches
#'
#' @param t1
#' Team for which bowling performance is required
#'
#' @param t2
#' t2=All gives the performance of the team against all opponents. Giving a opposing team (Australia, India
#' ) will give the performance against this team
#'
#' @param plot
#' plot=1 (static),plot=2(interactive),plot=3(table)
#'
#' @return None or data fame
#' A data frame with the bowling performance in alll matches against all oppositions
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' #Get all matches between India and other opposition
#' matches <-getAllMatchesAllOpposition("India",dir="../data/",save=TRUE)
#'
#' # Or load directly from saved file
#' # load("allMatchesAllOpposition-India.RData")
#'
#' teamBowlingWicketRunsAllOppnAllMatches(matches,t1="India",t2="All",plot=TRUE)
#' m <-teamBowlingWicketRunsAllOppnAllMatches(matches,t1="India",t2="All",plot=FALSE)
#' }
#'
#' @seealso
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesMain}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamBowlingWicketRunsAllOppnAllMatches <- function(matches,t1,t2="All",plot=1){
noBalls=wides=team=runs=bowler=wicketKind=wicketPlayerOut=NULL
ggplotly=NULL
team=bowler=ball=wides=noballs=runsConceded=overs=NULL
over=wickets=NULL
a <- NULL
if(t2 == "All"){
a <-filter(matches,team==t1)
} else {
a <-filter(matches,team==t2)
}
a1 <- unlist(strsplit(a$ball[1],"\\."))
# Create a string for substitution 1st or 2nd
a2 <- paste(a1[1],"\\.",sep="")
# only wides and noballs need to be included with runs for bowlers.
# Note: byes and legbyes should not be included
b <- a %>%
select(bowler,ball,noballs,wides,runs,wicketKind,wicketPlayerOut) %>%
#mutate(over=gsub("1st\\.","",ball)) %>%
mutate(over=gsub(a2,"",ball)) %>%
mutate(over=gsub("\\.\\d+","",over))
#Compute number of wickets (remove nobody)
c <- b %>%
select(bowler,wicketKind,wicketPlayerOut) %>%
filter(wicketPlayerOut != "nobody")
# Count wickets by bowlers
d <- summarise(group_by(c,bowler),wickets=length(wicketPlayerOut))
# Calculate runs
e <- summarise(group_by(b,bowler,over),sum(runs,wides,noballs))
names(e) <- c("bowler","over","runs")
#Compute total runs conceded (runs_wides+noballs)
f <- summarize(group_by(e,bowler),runsConceded=sum(runs))
# Join the runs conceded with the wickets taken
g <- full_join(f,d,by="bowler")
# Set the NAs (0 wickets) to 0
if(sum(is.na(g$wickets)) != 0){
g[is.na(g$wickets),]$wickets=0
}
# Pick the top 10 bowlers
h <- arrange(g,desc(wickets))
k <- h[1:10,]
if(plot==1){
plot.title <- paste(t1,"vs",t2,"wicket Runs of bowlers")
ggplot(data=k,aes(x=factor(wickets),y=runsConceded,fill=factor(wickets))) +
facet_grid( ~ bowler) + geom_bar(stat="identity") +
xlab("Number of wickets") + ylab('Runs conceded') +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),"")))) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
} else if(plot == 2){ #ggplotly
plot.title <- paste(t1,"vs",t2,"wicket Runs of bowlers")
ggplot(data=k,aes(x=factor(wickets),y=runsConceded,fill=factor(wickets))) +
facet_grid( ~ bowler) + geom_bar(stat="identity") +
xlab("Number of wickets") + ylab('Runs conceded') +
ggtitle(plot.title) +
theme(axis.text.x = element_text(angle = 90, hjust = 1))
}else{
k
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBowlingWicketRunsAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 21 Mar 2016
# Function: teamBowlingWicketRunsMatch
# This function computes the performance of bowlers of team with the runs conceded
#
#
###########################################################################################
#' @title
#' Team bowling wickets runs conceded in match
#'
#' @description
#' This function computes returns the wickets taken and runs conceded bowlers in a match between 2 teams.
#' The user can choose to plot or return a dataframe
#'
#' @usage
#' teamBowlingWicketRunsMatch(match,theTeam,opposition,plot=1)
#'
#' @param match
#' The match between the teams
#'
#' @param theTeam
#' Team for which bowling performance is required
#'
#' @param opposition
#' The opposition team
#'
#' @param plot
#' plot=1 (static),plot=2(interactive),plot=3(table)
#'
#' @return None or data fame
#' A data frame with the bowling performance in all matches against all oppositions
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' #Get the match details
#' a <- getMatchDetails("England","Pakistan","2006-09-05",dir="../temp")
#'
#' teamBowlingWicketRunsMatch(a,"England","Pakistan",plot=FALSE)
#' teamBowlingWicketRunsMatch(a,"Pakistan","England")
#' }
#'
#' @seealso
#' \code{\link{teamBowlingWicketMatch}}\cr
#' \code{\link{teamBowlingWicketRunsMatch}}\cr
#' \code{\link{teamBowlersVsBatsmenMatch}}\cr
#'
#' @export
#'
teamBowlingWicketRunsMatch <- function(match,theTeam,opposition, plot=1){
print("wicketruns")
noBalls=wides=team=runs=bowler=wicketKind=wicketPlayerOut=NULL
ggplotly=NULL
team=bowler=ball=wides=noballs=runsConceded=overs=over=wickets=NULL
# The performance of bowlers of the team is got when the other side is batting. Hence '!-"
# Filter the bowler's performance
a <-filter(match,team!=theTeam)
# Compute the maidens,runs conceded and overs for the bowlers
a1 <- unlist(strsplit(a$ball[1],"\\."))
# Create a string for substitution 1st or 2nd
a2 <- paste(a1[1],"\\.",sep="")
# only wides and noballs need to be included with runs for bowlers.
# Note: byes and legbyes should not be included
b <- a %>%
select(bowler,ball,noballs,wides,runs,wicketKind,wicketPlayerOut) %>%
#mutate(over=gsub("1st\\.","",ball)) %>%
mutate(over=gsub(a2,"",ball)) %>%
mutate(over=gsub("\\.\\d+","",over))
#Calculate the number of maiden overs
c <- summarise(group_by(b,bowler,over),sum(runs,wides,noballs))
names(c) <- c("bowler","over","runsConceded")
d <-summarize(group_by(c,bowler),maidens=sum(runsConceded==0))
#Compute total runs conceded (runs_wides+noballs)
e <- summarize(group_by(c,bowler),runs=sum(runsConceded))
# Calculate the number of overs bowled by each bwler
f <- select(c,bowler,over)
g <- summarise(group_by(f,bowler),overs=length(unique(over)))
print("wicketruns1")
#Compute number of wickets
h <- b %>%
select(bowler,wicketKind,wicketPlayerOut) %>%
filter(wicketPlayerOut != "nobody")
i <- summarise(group_by(h,bowler),wickets=length(unique(wicketPlayerOut)))
#Join the over & maidens
j <- full_join(g,d,by="bowler")
# Add runs
k <- full_join(j,e,by="bowler")
# Add wickets
l <- full_join(k,i,by="bowler")
#l$wickets = as.character(l$wickets)
#print(l$wickets)
# Set NAs to 0
l$wickets=as.numeric(l$wickets)
if(sum(is.na(l$wickets)) != 0){
l[is.na(l$wickets),]$wickets=0
}
# Plot or ourput data frame
if(plot == 1){ #ggplot2
plot.title <- paste(theTeam,"Wicket vs Runs conceded (against",opposition,")")
p <- ggplot(data=l,aes(x=factor(wickets),y=runs,fill=factor(wickets))) +
facet_grid(. ~ bowler,scales = "free_x", space = "free_x") +
geom_bar(stat="identity") +
xlab("Number of wickets") + ylab("Total runs conceded") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),"")))) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
theme(plot.title = element_text(size=14,margin=margin(10)))
p
} else if(plot == 2){ #ggplotly
plot.title <- paste(theTeam,"Wicket vs Runs conceded (against",opposition,")")
p <- ggplot(data=l,aes(x=factor(wickets),y=runs,fill=factor(wickets))) +
facet_grid(. ~ bowler,scales = "free_x", space = "free_x") +
geom_bar(stat="identity") +
xlab("Number of wickets") + ylab("Total runs conceded") +
ggtitle(plot.title) +
theme(axis.text.x = element_text(angle = 90, hjust = 1)) +
theme(plot.title = element_text(size=14,margin=margin(10)))
ggplotly(p)
}
else {
l
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamBowlingWicketRunsMatch.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 4 Nov 2021
# Function: teamERAcrossOvers
# This function the plots economy rate in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the ER in powerplay, middle and death overs
#'
#' @description
#' This function plots the runs in in powerplay, middle and death overs
#'
#' @usage
#' teamERAcrossOvers(match,t1,t2,plot=1)
#'
#' @param match
#' The dataframe of the match
#'
#' @param t1
#' The 1st team of the match
#'
#' @param t2
#' the 2nd team in the match
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Plot tne match worm plot
#' teamERAcrossOvers(match,'England',"Pakistan")
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
teamERAcrossOvers <- function(match,t1,t2,plot=1) {
team=ball=totalRuns=total=str_extract=type=ER=opposition=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(match,team==t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,team,totalRuns)
a3 <- a2 %>% group_by(team) %>% summarise(total=sum(totalRuns),count=n())
a3$ER=ifelse(dim(a3)[1]==0, 0,a3$total/a3$count * 6)
if(dim(a3)[1]!=0){
a3$type="1-Power Play"
a3$opposition=t2
}
# Middle overs I
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,team,totalRuns)
b3 <- b2 %>% group_by(team) %>% summarise(total=sum(totalRuns),count=n())
b3$ER=ifelse(dim(b3)[1]==0, 0,b3$total/b3$count * 6)
if(dim(b3)[1]!=0){
b3$type="2-Middle overs"
b3$opposition=t2
}
##Death overs
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,team,totalRuns)
c3 <- c2 %>% group_by(team) %>% summarise(total=sum(totalRuns),count=n())
c3$ER=ifelse(dim(c3)[1]==0, 0,c3$total/c3$count * 6)
if(dim(c3)[1]!=0){
c3$type="3-Death overs"
c3$opposition=t2
}
####################
# Filter the performance of team2
a <-filter(match,team==t2)
# Power play
a11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a21 <- select(a11,team,totalRuns)
a31 <- a21 %>% group_by(team) %>% summarise(total=sum(totalRuns),count=n())
a31$ER=ifelse(dim(a31)[1]==0, 0,a31$total/a31$count * 6)
if(dim(a31)[1]!=0){
a31$type="1-Power Play"
a31$opposition=t1
}
# Middle overs I
b11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b21 <- select(b11,team,totalRuns)
b31 <- b21 %>% group_by(team) %>% summarise(total=sum(totalRuns),count=n())
b31$ER=ifelse(dim(b31)[1]==0, 0,b31$total/b31$count * 6)
if(dim(b31)[1]!=0){
b31$type="2-Middle overs"
b31$opposition=t1
}
##Death overs
c11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c21 <- select(c11,team,totalRuns)
c31 <- c21 %>% group_by(team) %>% summarise(total=sum(totalRuns),count=n())
c31$ER=ifelse(dim(c31)[1]==0, 0,c31$total/c31$count * 6)
if(dim(c31)[1]!=0){
c31$type="3-Death overs"
c31$opposition=t1
}
m=rbind(a3,b3,c3,a31,b31,c31)
plot.title= paste("Economy rate across 20 overs of ",t1, "and", t2, sep=" ")
# Plot both lines
if(plot ==1){ #ggplot2
ggplot(m,aes(x=type, y=ER, fill=opposition)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),""))))
}else { #ggplotly
g <- ggplot(m,aes(x=type, y=ER, fill=opposition)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamERAcrossOvers.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 5 Nov 2021
# Function: teamERAcrossOversAllOppnAllMatches
# This function computes economy rate across overs in all matches against all opposition in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the ER by team against all team in powerplay, middle and death overs in all matches
#'
#' @description
#' This function plots the ER by team against all team in in powerplay, middle and death overs
#'
#' @usage
#' teamERAcrossOversAllOppnAllMatches(matches,t1,plot=1)
#'
#' @param matches
#' The dataframe of the matches
#'
#' @param t1
#' The 1st team of the match
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Plot tne match worm plot
#' teamERAcrossOversAllOppnAllMatches(matches,'England',"Pakistan")
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
teamERAcrossOversAllOppnAllMatches <- function(matches,t1,plot=1) {
team=ball=totalRuns=total=ER=type=meanER=str_extract=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team==t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,team,date,totalRuns)
a3 <- a2 %>% group_by(team,date) %>% summarise(total=sum(totalRuns),count=n())
a3$ER=a3$total/a3$count * 6
a4 = a3 %>% select(team,ER) %>% summarise(meanER=mean(ER))
a4$type="1-Power Play"
# Middle overs I
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,team,date,totalRuns)
b3 <- b2 %>% group_by(team,date) %>% summarise(total=sum(totalRuns),count=n())
b3$ER=b3$total/b3$count * 6
b4 = b3 %>% select(team,ER) %>% summarise(meanER=mean(ER))
b4$type="2-Middle Overs"
##Death overs
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,team,date,totalRuns)
c3 <- c2 %>% group_by(team,date) %>% summarise(total=sum(totalRuns),count=n())
c3$ER=c3$total/c3$count * 6
c4 = c3 %>% select(team,ER) %>% summarise(meanER=mean(ER))
c4$type="3-Death Overs"
m=rbind(a4,b4,c4)
plot.title= paste("Wickets across 20 overs by ",t1,"in all matches against all teams", sep=" ")
# Plot both lines
if(plot ==1){ #ggplot2
ggplot(m,aes(x=type, y=meanER, fill=t1)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),""))))
}else { #ggplotly
g <- ggplot(m,aes(x=type, y=meanER, fill=t1)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamERAcrossOversAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 5 Nov 2021
# Function: teamERAcrossOversOppnAllMatches
# This function computes economy rate across overs in all matches against opposition in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the ER by team against team in powerplay, middle and death overs in all matches
#'
#' @description
#' This function plots the ER by team against team in in powerplay, middle and death overs
#'
#' @usage
#' teamERAcrossOversOppnAllMatches(matches,t1,t2,plot=1)
#'
#' @param matches
#' The dataframe of the matches
#'
#' @param t1
#' The 1st team of the match
#'
#' @param t2
#' the 2nd team in the match
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Plot tne match worm plot
#' teamERAcrossOversOppnAllMatches(matches,'England',"Pakistan")
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
teamERAcrossOversOppnAllMatches <- function(matches,t1,t2,plot=1) {
team=ball=totalRuns=total=type=meanER=opposition=ER=str_extract=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team==t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,team,date,totalRuns)
a3 <- a2 %>% group_by(team,date) %>% summarise(total=sum(totalRuns),count=n())
a3$ER=a3$total/a3$count * 6
a4 = a3 %>% select(team,ER) %>% summarise(meanER=mean(ER))
a4$opposition=t2
a4$type="1-Power Play"
# Middle overs I
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,team,date,totalRuns)
b3 <- b2 %>% group_by(team,date) %>% summarise(total=sum(totalRuns),count=n())
b3$ER=b3$total/b3$count * 6
b4 = b3 %>% select(team,ER) %>% summarise(meanER=mean(ER))
b4$opposition=t2
b4$type="2-Middle Overs"
##Death overs
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,team,date,totalRuns)
c3 <- c2 %>% group_by(team,date) %>% summarise(total=sum(totalRuns),count=n())
c3$ER=c3$total/c3$count * 6
c4 = c3 %>% select(team,ER) %>% summarise(meanER=mean(ER))
c4$opposition=t2
c4$type="3-Death Overs"
####################
# Filter the performance of team2
a <-filter(matches,team==t2)
# Power play
a11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a21 <- select(a11,team,date,totalRuns)
a31 <- a21 %>% group_by(team,date) %>% summarise(total=sum(totalRuns),count=n())
a31$ER=a31$total/a31$count * 6
a41 = a31 %>% select(team,ER) %>% summarise(meanER=mean(ER))
a41$opposition=t1
a41$type="1-Power Play"
# Middle overs I
b11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b21 <- select(b11,team,date,totalRuns)
b31 <- b21 %>% group_by(team,date) %>% summarise(total=sum(totalRuns),count=n())
b31$ER=b31$total/b31$count * 6
b41 = b31 %>% select(team,ER) %>% summarise(meanER=mean(ER))
b41$opposition=t1
b41$type="2-Middle Overs"
##Death overs
c11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c21 <- select(c11,team,date,totalRuns)
c31 <- c21 %>% group_by(team,date) %>% summarise(total=sum(totalRuns),count=n())
c31$ER=c31$total/c31$count * 6
c41 = c31 %>% select(team,ER) %>% summarise(meanER=mean(ER))
c41$opposition=t1
c41$type="3-Death Overs"
m=rbind(a4,b4,c4,a41,b41,c41)
plot.title= paste("Wickets across 20 overs by ",t1, "and", t2, "in all matches", sep=" ")
# Plot both lines
if(plot ==1){ #ggplot2
ggplot(m,aes(x=type, y=meanER, fill=opposition)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),""))))
}else { #ggplotly
g <- ggplot(m,aes(x=type, y=meanER, fill=opposition)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamERAcrossOversOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 26 Nov 2021
# Function: teamRunSRDeathOversPlotAllOppnAllMatches
# This function plot the runs vs SR for the team batsman during death overs against all opposition in
# in all matches
#
#
###########################################################################################
#' @title
#' Team batting plots runs vs SR in death overs for team against all oppositions in all matches
#'
#' @description
#' This function computes and plots runs vs SR in death overs of a team in all matches against all
#' oppositions.
#'
#' @usage
#' teamRunSRDeathOversPlotAllOppnAllMatches(matches,t1,plot=1)
#'
#' @param matches
#' All matches of the team in all matches with all oppositions
#'
#' @param t1
#' The team for which the the batting partnerships are sought
#'
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#'
#' # Top batsman is displayed in descending order of runs
#' teamRunSRDeathOversPlotAllOppnAllMatches(matches,t1,plot=1)
#'
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBowlingWicketRunsAllOppnAllMatches}}
#'
#' @export
#'
teamRunSRDeathOversPlotAllOppnAllMatches <- function(matches,t1,plot=1) {
team=ball=totalRuns=total=str_extract=batsman=runs=quantile=quadrant=SRDeathOvers=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team==t1)
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
a2 <- select(a1,ball,totalRuns,batsman,date)
a3 <- a2 %>% group_by(batsman) %>% summarise(runs=sum(totalRuns),count=n(), SRDeathOvers=runs/count*100)
x_lower <- quantile(a3$runs,p=0.66,na.rm = TRUE)
y_lower <- quantile(a3$SRDeathOvers,p=0.66,na.rm = TRUE)
plot.title <- paste(t1, " Runs vs SR in Death overs in all matches against all opposition")
if(plot == 1){ #ggplot2
a3 %>%
mutate(quadrant = case_when(runs > x_lower & SRDeathOvers > y_lower ~ "Q1",
runs <= x_lower & SRDeathOvers > y_lower ~ "Q2",
runs <= x_lower & SRDeathOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SRDeathOvers,color=quadrant)) +
geom_text(aes(runs,SRDeathOvers,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs - Death overs") + ylab("Strike rate - Death overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- a3 %>%
mutate(quadrant = case_when(runs > x_lower & SRDeathOvers > y_lower ~ "Q1",
runs <= x_lower & SRDeathOvers > y_lower ~ "Q2",
runs <= x_lower & SRDeathOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SRDeathOvers,color=quadrant)) +
geom_text(aes(runs,SRDeathOvers,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs - Death overs") + ylab("Strike rate - Death overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamRunSRDeathOversPlotAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 28 Nov 2021
# Function: teamRunSRDeathOversPlotMatch
# This function plot the runs vs SR for the team batsman during death overs against opposition in match
#
#
###########################################################################################
#' @title
#' Team batting plots runs vs SR in death overs for team in match
#'
#' @description
#' This function computes and plots runs vs SR in death overs of a team in match against
#' opposition.
#'
#' @usage
#' teamRunSRDeathOversPlotMatch(match,t1, t2, plot=1)
#'
#' @param match
#' Match
#'
#' @param t1
#' The team
#'
#' @param t2
#' The opposition team
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#'
#' # Top batsman is displayed in descending order of runs
#' teamRunSRDeathOversPlotMatch(match,t1="India",t2="England")
#'
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBowlingWicketRunsAllOppnAllMatches}}
#'
#' @export
#'
teamRunSRDeathOversPlotMatch <- function(match,t1,t2, plot=1) {
team=ball=totalRuns=total=str_extract=batsman=runs=quantile=quadrant=SRDeathOvers=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(match,team==t1)
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
a2 <- select(a1,ball,totalRuns,batsman,date)
a3 <- a2 %>% group_by(batsman) %>% summarise(runs=sum(totalRuns),count=n(), SRDeathOvers=runs/count*100)
x_lower <- quantile(a3$runs,p=0.66,na.rm = TRUE)
y_lower <- quantile(a3$SRDeathOvers,p=0.66,na.rm = TRUE)
plot.title <- paste(t1, " Runs vs SR in Death overs against ", t2,sep="")
if(plot == 1){ #ggplot2
a3 %>%
mutate(quadrant = case_when(runs > x_lower & SRDeathOvers > y_lower ~ "Q1",
runs <= x_lower & SRDeathOvers > y_lower ~ "Q2",
runs <= x_lower & SRDeathOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SRDeathOvers,color=quadrant)) +
geom_text(aes(runs,SRDeathOvers,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs - Death overs") + ylab("Strike rate - Death overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- a3 %>%
mutate(quadrant = case_when(runs > x_lower & SRDeathOvers > y_lower ~ "Q1",
runs <= x_lower & SRDeathOvers > y_lower ~ "Q2",
runs <= x_lower & SRDeathOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SRDeathOvers,color=quadrant)) +
geom_text(aes(runs,SRDeathOvers,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs - Death overs") + ylab("Strike rate - Death overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamRunSRDeathOversPlotMatch.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 26 Nov 2021
# Function: teamRunSRDeathOversPlotOppnAllMatches
# This function plot the runs vs SR for the team batsman during death overs against opposition in
# in all matches
#
#
###########################################################################################
#' @title
#' Team batting plots runs vs SR in death overs for team against opposition in all matches
#'
#' @description
#' This function computes and plots runs vs SR in middle overs of a team in all matches against
#' opposition.
#'
#' @usage
#' teamRunSRDeathOversPlotOppnAllMatches(matches,t1, t2, plot=1)
#'
#' @param matches
#' All matches of the team in all matches with all oppositions
#'
#' @param t1
#' The team
#'
#' @param t2
#' The opposition team
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#'
#' # Top batsman is displayed in descending order of runs
#' teamRunSRDeathOversPlotOppnAllMatches(matches,t1="India",t2="England")
#'
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBowlingWicketRunsAllOppnAllMatches}}
#'
#' @export
#'
teamRunSRDeathOversPlotOppnAllMatches <- function(matches,t1,t2, plot=1) {
team=ball=totalRuns=total=str_extract=batsman=runs=quantile=quadrant=SRDeathOvers=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team==t1)
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
a2 <- select(a1,ball,totalRuns,batsman,date)
a3 <- a2 %>% group_by(batsman) %>% summarise(runs=sum(totalRuns),count=n(), SRDeathOvers=runs/count*100)
x_lower <- quantile(a3$runs,p=0.66,na.rm = TRUE)
y_lower <- quantile(a3$SRDeathOvers,p=0.66,na.rm = TRUE)
plot.title <- paste(t1, " Runs vs SR in Death overs in all matches against ", t2)
if(plot == 1){ #ggplot2
a3 %>%
mutate(quadrant = case_when(runs > x_lower & SRDeathOvers > y_lower ~ "Q1",
runs <= x_lower & SRDeathOvers > y_lower ~ "Q2",
runs <= x_lower & SRDeathOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SRDeathOvers,color=quadrant)) +
geom_text(aes(runs,SRDeathOvers,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs - Death overs") + ylab("Strike rate - Death overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- a3 %>%
mutate(quadrant = case_when(runs > x_lower & SRDeathOvers > y_lower ~ "Q1",
runs <= x_lower & SRDeathOvers > y_lower ~ "Q2",
runs <= x_lower & SRDeathOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SRDeathOvers,color=quadrant)) +
geom_text(aes(runs,SRDeathOvers,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs - Death overs") + ylab("Strike rate - Death overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamRunSRDeathOversPlotOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 4 Nov 2021
# Function: teamRunsAcrossOvers
# This function the plots runs scored in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the runs in powerplay, middle and death overs
#'
#' @description
#' This function plots the runs in in powerplay, middle and death overs
#'
#' @usage
#' teamRunsAcrossOvers(match,t1,t2,plot=1)
#'
#' @param match
#' The dataframe of the match
#'
#' @param t1
#' The 1st team of the match
#'
#' @param t2
#' the 2nd team in the match
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Plot tne match worm plot
#' teamRunsAcrossOvers(match,'England',"Pakistan")
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
teamRunsAcrossOvers <- function(match,t1,t2,plot=1) {
team=ball=totalRuns=total=type=str_extract=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(match,team==t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,team,totalRuns)
a3 <- a2 %>% group_by(team) %>% summarise(total=sum(totalRuns))
a3$type="1-Power Play"
# Middle overs I
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,team,totalRuns)
b3 <- b2 %>% group_by(team) %>% summarise(total=sum(totalRuns))
b3$type="2-Middle Overs"
#Death overs
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,team,totalRuns)
c3 <- c2 %>% group_by(team) %>% summarise(total=sum(totalRuns))
c3$type="3-Death Overs"
####################
# Filter the performance of team2
a <-filter(match,team==t2)
# Power play
a11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a21 <- select(a11,team,totalRuns)
a31 <- a21 %>% group_by(team) %>% summarise(total=sum(totalRuns))
a31$type="1-Power Play"
# Middle overs I
b11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b21 <- select(b11,team,totalRuns)
b31 <- b21 %>% group_by(team) %>% summarise(total=sum(totalRuns))
b31$type="2-Middle Overs"
#Death overs
c11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1,20.0))
c21 <- select(c11,team,totalRuns)
c31 <- c21 %>% group_by(team) %>% summarise(total=sum(totalRuns))
c31$type="3-Death Overs"
m=rbind(a3,b3,c3,a31,b31,c31)
# Plot both lines
if(plot ==1){ #ggplot2
plot.title= paste("Runs scored across 20 overs by ",t1, "and", t2, sep=" ")
ggplot(m,aes(x=type, y=total, fill=team)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),""))))
}else { #ggplotly
plot.title= paste("Runs scored across 20 overs by ",t1, "and", t2, sep=" ")
g <- ggplot(m,aes(x=type, y=total, fill=team)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamRunsAcrossOvers.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 5 Nov 2021
# Function: teamRunsAcrossOversAllOppnAllMatches
# This function computes runs across overs in all matches against all opposition in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the runs by team against all team in powerplay, middle and death overs
#'
#' @description
#' This function plots the runs by team against all teams in in powerplay, middle and death overs
#'
#' @usage
#' teamRunsAcrossOversAllOppnAllMatches(matches,t1,plot=1)
#'
#' @param matches
#' The dataframe of the matches
#'
#' @param t1
#' The team for which the runs is required
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Plot tne match worm plot
#' teamRunsAcrossOversAllOppnAllMatches(matches,'England')
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
teamRunsAcrossOversAllOppnAllMatches <- function(matches,t1,plot=1) {
team=ball=totalRuns=total=meanRuns=type=str_extract=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team==t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,team,totalRuns,date)
a3 <- a2 %>% group_by(team,date) %>% summarise(total=sum(totalRuns))
a4 = a3 %>% summarise(meanRuns=mean(total))
a4$type="1-Power Play"
# Middle overs I
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,team,totalRuns,date)
b3 <- b2 %>% group_by(team,date) %>% summarise(total=sum(totalRuns))
b4 = b3 %>% summarise(meanRuns=mean(total))
b4$type="2-Middle Overs"
#Death overs
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,team,totalRuns,date)
c3 <- c2 %>% group_by(team,date) %>% summarise(total=sum(totalRuns))
c4 = c3 %>% summarise(meanRuns=mean(total))
c4$type="3-Death Overs"
m=rbind(a4,b4,c4)
plot.title= paste("Mean runs across 20 overs by ",t1, "in all matches against all teams", sep=" ")
# Plot both lines
if(plot ==1){ #ggplot2
ggplot(m,aes(x=type, y=meanRuns, fill=team)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),""))))
}else { #ggplotly
g <- ggplot(m,aes(x=type, y=meanRuns, fill=team)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamRunsAcrossOversAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 4 Nov 2021
# Function: teamRunsAcrossOversOppnAllMatches
# This function computes runs across overs in all matches against opposition in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the runs by team against team in powerplay, middle and death overs
#'
#' @description
#' This function plots the runs by team against team in in powerplay, middle and death overs
#'
#' @usage
#' teamRunsAcrossOversOppnAllMatches(matches,t1,t2,plot=1)
#'
#' @param matches
#' The dataframe of the matches
#'
#' @param t1
#' The 1st team of the match
#'
#' @param t2
#' the 2nd team in the match
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Plot tne match worm plot
#' teamRunsAcrossOversOppnAllMatches(matches,'England',"Pakistan")
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
teamRunsAcrossOversOppnAllMatches <- function(matches,t1,t2,plot=1) {
team=ball=totalRuns=total=meanRuns=type=str_extract=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team==t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,team,totalRuns,date)
a3 <- a2 %>% group_by(team,date) %>% summarise(total=sum(totalRuns))
a4 = a3 %>% summarise(meanRuns=mean(total))
a4$type="1-Power Play"
# Middle overs I
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,team,totalRuns,date)
b3 <- b2 %>% group_by(team,date) %>% summarise(total=sum(totalRuns))
b4 = b3 %>% summarise(meanRuns=mean(total))
b4$type="2-Middle Overs"
#Death overs
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,team,totalRuns,date)
c3 <- c2 %>% group_by(team,date) %>% summarise(total=sum(totalRuns))
c4 = c3 %>% summarise(meanRuns=mean(total))
c4$type="3-Death Overs"
####################
# Filter the performance of team2
a <-filter(matches,team==t2)
# Power play
a11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a21 <- select(a11,team,totalRuns,date)
a31 <- a21 %>% group_by(team,date) %>% summarise(total=sum(totalRuns))
a41 = a31 %>% summarise(meanRuns=mean(total))
a41$type="1-Power Play"
# Middle overs I
b11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b21 <- select(b11,team,totalRuns,date)
b31 <- b21 %>% group_by(team,date) %>% summarise(total=sum(totalRuns))
b41 = b31 %>% summarise(meanRuns=mean(total))
b41$type="2-Middle Overs"
# Death overs 2
c11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1,20.0))
c21 <- select(c11,team,totalRuns,date)
c31 <- c21 %>% group_by(team,date) %>% summarise(total=sum(totalRuns))
c41 = c31 %>% summarise(meanRuns=mean(total))
c41$type="3-Death Overs"
m=rbind(a4,b4,c4,a41,b41,c41)
plot.title= paste("Mean runs across 20 overs by ",t1, "and", t2, "in all matches", sep=" ")
# Plot both lines
if(plot ==1){ #ggplot2
ggplot(m,aes(x=type, y=meanRuns, fill=team)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),""))))
}else { #ggplotly
g <- ggplot(m,aes(x=type, y=meanRuns, fill=team)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamRunsAcrossOversOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 26 Nov 2021
# Function: teamRunsSRMiddleOversPlotAllOppnAllMatches
# This function plot the runs vs SR for the team batsman during middle overs against all opposition in
# in all matches
#
#
###########################################################################################
#' @title
#' Team batting plots runs vs SR in middle overs for team against all oppositions in all matches
#'
#' @description
#' This function computes and plots runs vs SR in middle overs of a team in all matches against all
#' oppositions.
#'
#' @usage
#' teamRunsSRMiddleOversPlotAllOppnAllMatches(matches,t1,plot=1)
#'
#' @param matches
#' All matches of the team in all matches with all oppositions
#'
#' @param t1
#' The team for which the the batting partnerships are sought
#'
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#'
#' # Top batsman is displayed in descending order of runs
#' teamRunsSRMiddleOversPlotAllOppnAllMatches(matches,t1,plot=1)
#'
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBowlingWicketRunsAllOppnAllMatches}}
#'
#' @export
#'
teamRunsSRMiddleOversPlotAllOppnAllMatches <- function(matches,t1,plot=1) {
team=ball=totalRuns=total=str_extract=batsman=runs=quantile=quadrant=SRMiddleOvers=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team==t1)
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
a2 <- select(a1,ball,totalRuns,batsman,date)
a3 <- a2 %>% group_by(batsman) %>% summarise(runs=sum(totalRuns),count=n(), SRMiddleOvers=runs/count*100)
x_lower <- quantile(a3$runs,p=0.66,na.rm = TRUE)
y_lower <- quantile(a3$SRMiddleOvers,p=0.66,na.rm = TRUE)
print("xx")
print(x_lower)
plot.title <- paste(t1, " Runs vs SR in Death overs in all matches against all opposition")
if(plot == 1){ #ggplot2
a3 %>%
mutate(quadrant = case_when(runs > x_lower & SRMiddleOvers > y_lower ~ "Q1",
runs <= x_lower & SRMiddleOvers > y_lower ~ "Q2",
runs <= x_lower & SRMiddleOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SRMiddleOvers,color=quadrant)) +
geom_text(aes(runs,SRMiddleOvers,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs - Middle overs") + ylab("Strike rate - Middle overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- a3 %>%
mutate(quadrant = case_when(runs > x_lower & SRMiddleOvers > y_lower ~ "Q1",
runs <= x_lower & SRMiddleOvers > y_lower ~ "Q2",
runs <= x_lower & SRMiddleOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SRMiddleOvers,color=quadrant)) +
geom_text(aes(runs,SRMiddleOvers,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs - Middle overs") + ylab("Strike rate - Middle overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamRunsSRMiddleOversPlotAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 26 Nov 2021
# Function: teamRunsSRPMiddleOversPlotMatch
# This function plot the runs vs SR for the team batsman during middle overs against opposition in match
#
#
###########################################################################################
#' @title
#' Team batting plots runs vs SR in middle overs for team in match
#'
#' @description
#' This function computes and plots runs vs SR in middle overs of a team in match against
#' opposition.
#'
#' @usage
#' teamRunsSRPMiddleOversPlotMatch(match,t1, t2, plot=1)
#'
#' @param match
#' Match
#'
#' @param t1
#' The team
#'
#' @param t2
#' The opposition team
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#'
#' # Top batsman is displayed in descending order of runs
#' teamRunsSRPMiddleOversPlotMatch(match,t1="India",t2="England")
#'
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBowlingWicketRunsAllOppnAllMatches}}
#'
#' @export
#'
teamRunsSRPMiddleOversPlotMatch <- function(match,t1,t2, plot=1) {
team=ball=totalRuns=total=str_extract=batsman=runs=quantile=quadrant=SRMiddleOvers=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(match,team==t1)
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
a2 <- select(a1,ball,totalRuns,batsman,date)
a3 <- a2 %>% group_by(batsman) %>% summarise(runs=sum(totalRuns),count=n(), SRMiddleOvers=runs/count*100)
x_lower <- quantile(a3$runs,p=0.66,na.rm = TRUE)
y_lower <- quantile(a3$SRMiddleOvers,p=0.66,na.rm = TRUE)
plot.title <- paste(t1, " Runs vs SR in Middle overs against ", t2,sep="")
if(plot == 1){ #ggplot2
a3 %>%
mutate(quadrant = case_when(runs > x_lower & SRMiddleOvers > y_lower ~ "Q1",
runs <= x_lower & SRMiddleOvers > y_lower ~ "Q2",
runs <= x_lower & SRMiddleOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SRMiddleOvers,color=quadrant)) +
geom_text(aes(runs,SRMiddleOvers,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs - Middle overs") + ylab("Strike rate - Middle overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- a3 %>%
mutate(quadrant = case_when(runs > x_lower & SRMiddleOvers > y_lower ~ "Q1",
runs <= x_lower & SRMiddleOvers > y_lower ~ "Q2",
runs <= x_lower & SRMiddleOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SRMiddleOvers,color=quadrant)) +
geom_text(aes(runs,SRMiddleOvers,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs - Middle overs") + ylab("Strike rate - Middle overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamRunsSRMiddleOversPlotMatch.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 26 Nov 2021
# Function: teamRunsSRPMiddleOversPlotOppnAllMatches
# This function plot the runs vs SR for the team batsman during middle overs against opposition in
# in all matches
#
#
###########################################################################################
#' @title
#' Team batting plots runs vs SR in middle overs for team against opposition in all matches
#'
#' @description
#' This function computes and plots runs vs SR in middle overs of a team in all matches against
#' opposition.
#'
#' @usage
#' teamRunsSRPMiddleOversPlotOppnAllMatches(matches,t1, t2, plot=1)
#'
#' @param matches
#' All matches of the team in all matches with all oppositions
#'
#' @param t1
#' The team
#'
#' @param t2
#' The opposition team
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#'
#' # Top batsman is displayed in descending order of runs
#' teamRunsSRPMiddleOversPlotOppnAllMatches(matches,t1="India",t2="England")
#'
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBowlingWicketRunsAllOppnAllMatches}}
#'
#' @export
#'
teamRunsSRPMiddleOversPlotOppnAllMatches <- function(matches,t1,t2, plot=1) {
team=ball=totalRuns=total=str_extract=batsman=runs=quantile=quadrant=SRMiddleOvers=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team==t1)
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
a2 <- select(a1,ball,totalRuns,batsman,date)
a3 <- a2 %>% group_by(batsman) %>% summarise(runs=sum(totalRuns),count=n(), SRMiddleOvers=runs/count*100)
x_lower <- quantile(a3$runs,p=0.66,na.rm = TRUE)
y_lower <- quantile(a3$SRMiddleOvers,p=0.66,na.rm = TRUE)
plot.title <- paste(t1, "Runs vs SR in Middle overs in all matches against ", t2)
if(plot == 1){ #ggplot2
a3 %>%
mutate(quadrant = case_when(runs > x_lower & SRMiddleOvers > y_lower ~ "Q1",
runs <= x_lower & SRMiddleOvers > y_lower ~ "Q2",
runs <= x_lower & SRMiddleOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SRMiddleOvers,color=quadrant)) +
geom_text(aes(runs,SRMiddleOvers,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs - Middle overs") + ylab("Strike rate - Middle overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- a3 %>%
mutate(quadrant = case_when(runs > x_lower & SRMiddleOvers > y_lower ~ "Q1",
runs <= x_lower & SRMiddleOvers > y_lower ~ "Q2",
runs <= x_lower & SRMiddleOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SRMiddleOvers,color=quadrant)) +
geom_text(aes(runs,SRMiddleOvers,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs - Middle overs") + ylab("Strike rate - Middle overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamRunsSRMiddleOversPlotOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 23 Nov 2021
# Function: teamRunsSRPlotAllOppnAllMatches
# This function computes the runs vs SR for the team batsman against all opposition in
# all matches
#
#
###########################################################################################
#' @title
#' Team batting plots runs vs SR for team against all oppositions in all matches
#'
#' @description
#' This function computes and plots runs vs SR of a team in all matches against all
#' oppositions.
#'
#' @usage
#' teamRunsSRPlotAllOppnAllMatches(matches,theTeam,plot=1)
#'
#' @param matches
#' All matches of the team in all matches with all oppositions
#'
#' @param theTeam
#' The team for which the the batting partnerships are sought
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return details
#' The data frame of the scorecard of the team in all matches against all oppositions
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' # Get all matches between India with all oppositions
#' matches <-getAllMatchesAllOpposition("India",dir="../data/",save=TRUE)
#'
#' # This can also be loaded from saved file
#' # load("allMatchesAllOpposition-India.RData")
#'
#' # Top batsman is displayed in descending order of runs
#' teamRunsSRPlotAllOppnAllMatches(matches,theTeam="India")
#'
#' # The best England players scorecard against India is shown
#' teamRunsSRPlotAllOppnAllMatches(matches,theTeam="England",plot=1)
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBowlingWicketRunsAllOppnAllMatches}}
#'
#' @export
#'
teamRunsSRPlotAllOppnAllMatches <- function(matches,theTeam, plot=1){
team=batsman=runs=fours=sixes=SR=quantile=quadrant=NULL
byes=legbyes=noballs=wides=ggplotly=NULL
a <-filter(matches,team==theTeam)
b <- select(a,batsman,runs)
names(b) <-c("batsman","runs")
#Compute the number of 4s
c <-
b %>%
mutate(fours=(runs>=4 & runs <6)) %>%
filter(fours==TRUE)
# Group by batsman. Count 4s
d <- summarise(group_by(c, batsman),fours=n())
# Get the total runs for each batsman
e <-summarise(group_by(a,batsman),sum(runs))
names(b) <-c("batsman","runs")
details <- full_join(e,d,by="batsman")
names(details) <-c("batsman","runs","fours")
f <-
b %>%
mutate(sixes=(runs ==6)) %>%
filter(sixes == TRUE)
# Group by batsman. COunt 6s
g <- summarise(group_by(f, batsman),sixes=n())
names(g) <-c("batsman","sixes")
#Full join with 4s and 6s
details <- full_join(details,g,by="batsman")
# Count the balls played by the batsman
ballsPlayed <-
a %>%
select(batsman,byes,legbyes,wides,noballs,runs) %>%
filter(wides ==0,noballs ==0,byes ==0,legbyes == 0) %>%
select(batsman,runs)
ballsPlayed<- summarise(group_by(ballsPlayed,batsman),count=n())
names(ballsPlayed) <- c("batsman","ballsPlayed")
details <- full_join(details,ballsPlayed,by="batsman")
details$SR= details$runs/details$ballsPlayed *100.00
cat("Total=",sum(details$runs),"\n")
details <- arrange(details,desc(runs),desc(sixes),desc(fours))
details <- select(details,batsman,ballsPlayed,fours,sixes,runs,SR)
x_lower <- quantile(details$runs,p=0.66, na.rm = TRUE)
y_lower <- quantile(details$SR,p=0.66, na.rm = TRUE)
plot.title <- paste(theTeam, "Runs vs SR against all opposition in all matches")
if(plot == 1){ #ggplot2
details %>%
mutate(quadrant = case_when(runs > x_lower & SR > y_lower ~ "Q1",
runs <= x_lower & SR > y_lower ~ "Q2",
runs <= x_lower & SR <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SR,color=quadrant)) +
geom_text(aes(runs,SR,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs") + ylab("Strike rate") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- details %>%
mutate(quadrant = case_when(runs > x_lower & SR > y_lower ~ "Q1",
runs <= x_lower & SR > y_lower ~ "Q2",
runs <= x_lower & SR <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SR,color=quadrant)) +
geom_text(aes(runs,SR,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs") + ylab("Strike rate") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamRunsSRPlotAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 23 Nov 2021
# Function: teamRunsSRPlotMatch
# This function plots the Runs vs SR of a team in a match
#
#
###########################################################################################
#' @title
#' Team Runs vs SR in match
#'
#' @description
#' This function computes and plots the Runs vs SR of a team in matches
#'
#' @usage
#' teamRunsSRPlotMatch(match,theTeam, opposition, plot=1)
#'
#' @param match
#' All matches of the team in all matches with all oppositions
#'
#' @param theTeam
#' The team for which the the batting partnerships are sought
#'
#' @param opposition
#' The opposition team
#'
#' @param plot
#' plot=1 (static),plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Top batsman is displayed in descending order of runs
#' teamRunsSRPlotMatch(matches,theTeam="India",opposition="England")
#'
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBowlingWicketRunsAllOppnAllMatches}}
#'
#' @export
#'
teamRunsSRPlotMatch <- function(match,theTeam,opposition,plot=1){
team=batsman=runs=fours=sixes=str_extract=batsman=runs=quantile=quadrant=SR=NULL
byes=legbyes=noballs=wides=ggplotly=NULL
a <-filter(match,team==theTeam)
b <- select(a,batsman,runs)
names(b) <-c("batsman","runs")
#Compute the number of 4s
c <-
b %>%
mutate(fours=(runs>=4 & runs <6)) %>%
filter(fours==TRUE)
# Group by batsman. Count 4s
d <- summarise(group_by(c, batsman),fours=n())
# Get the total runs for each batsman
e <-summarise(group_by(a,batsman),sum(runs))
names(b) <-c("batsman","runs")
details <- full_join(e,d,by="batsman")
names(details) <-c("batsman","runs","fours")
f <-
b %>%
mutate(sixes=(runs ==6)) %>%
filter(sixes == TRUE)
# Group by batsman. COunt 6s
g <- summarise(group_by(f, batsman),sixes=n())
names(g) <-c("batsman","sixes")
#Full join with 4s and 6s
details <- full_join(details,g,by="batsman")
# Count the balls played by the batsman
ballsPlayed <-
a %>%
select(batsman,byes,legbyes,wides,noballs,runs) %>%
filter(wides ==0,noballs ==0,byes ==0,legbyes == 0) %>%
select(batsman,runs)
ballsPlayed<- summarise(group_by(ballsPlayed,batsman),count=n())
names(ballsPlayed) <- c("batsman","ballsPlayed")
details <- full_join(details,ballsPlayed,by="batsman")
details$SR= details$runs/details$ballsPlayed *100.00
cat("Total=",sum(details$runs),"\n")
details <- arrange(details,desc(runs),desc(sixes),desc(fours))
details <- select(details,batsman,ballsPlayed,fours,sixes,runs,SR)
details[is.na(details)] <- 0
x_lower <- quantile(details$runs,p=0.66,na.rm = TRUE)
y_lower <- quantile(details$SR,p=0.66,na.rm = TRUE)
plot.title <- paste("Runs vs SR of ", theTeam, "in match against", opposition)
if(plot == 1){ #ggplot2
details %>%
mutate(quadrant = case_when(runs > x_lower & SR > y_lower ~ "Q1",
runs <= x_lower & SR > y_lower ~ "Q2",
runs <= x_lower & SR <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SR,color=quadrant)) +
geom_text(aes(runs,SR,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs") + ylab("Strike rate") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- details %>%
mutate(quadrant = case_when(runs > x_lower & SR > y_lower ~ "Q1",
runs <= x_lower & SR > y_lower ~ "Q2",
runs <= x_lower & SR <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SR,color=quadrant)) +
xlab("Runs") + ylab("Strike rate") +
geom_text(aes(runs,SR,label=batsman,color=quadrant)) + geom_point() +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamRunsSRPlotMatch.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 19 Nov 2021
# Function: teamRunsSRPlotOppnAllMatches
# This function computes the Runs vs SR of the team batsman against opposition in
# all matches
#
#
###########################################################################################
#' @title
#' Team batting Runs vs SR against oppositions in all matches
#'
#' @description
#' This function computes and plots the Runs vs SR of a team in all matches against an
#' oppositions.
#'
#' @usage
#' teamRunsSRPlotOppnAllMatches(matches,t1,t2,plot=1)
#'
#' @param matches
#' All matches of the team in all matches with opposition
#'
#' @param t1
#' The team t
#'
#' @param t2
#' The opposition team
#'
#'@param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Top batsman is displayed in descending order of runs
#' teamRunsSRPlotOppnAllMatches(matches,theTeam="India")
#'
#' # The best England players scorecard against India is shown
#' teamRunsSRPlotOppnAllMatches(matches,theTeam="England")
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBowlingWicketRunsAllOppnAllMatches}}
#'
#' @export
#'
teamRunsSRPlotOppnAllMatches <- function(matches,t1,t2,plot=1){
team=batsman=runs=fours=sixes=SR=quantile=quadrant=NULL
byes=legbyes=noballs=wides=ggplotly=NULL
a <-filter(matches,team==t1)
b <- select(a,batsman,runs)
names(b) <-c("batsman","runs")
#Compute the number of 4s
c <-
b %>%
mutate(fours=(runs>=4 & runs <6)) %>%
filter(fours==TRUE)
# Group by batsman. Count 4s
d <- summarise(group_by(c, batsman),fours=n())
# Get the total runs for each batsman
e <-summarise(group_by(a,batsman),sum(runs))
names(b) <-c("batsman","runs")
details <- full_join(e,d,by="batsman")
names(details) <-c("batsman","runs","fours")
f <-
b %>%
mutate(sixes=(runs ==6)) %>%
filter(sixes == TRUE)
# Group by batsman. COunt 6s
g <- summarise(group_by(f, batsman),sixes=n())
names(g) <-c("batsman","sixes")
#Full join with 4s and 6s
details <- full_join(details,g,by="batsman")
# Count the balls played by the batsman
ballsPlayed <-
a %>%
select(batsman,byes,legbyes,wides,noballs,runs) %>%
filter(wides ==0,noballs ==0,byes ==0,legbyes == 0) %>%
select(batsman,runs)
ballsPlayed<- summarise(group_by(ballsPlayed,batsman),count=n())
names(ballsPlayed) <- c("batsman","ballsPlayed")
details <- full_join(details,ballsPlayed,by="batsman")
details$SR= details$runs/details$ballsPlayed *100.00
cat("Total=",sum(details$runs),"\n")
details <- arrange(details,desc(runs),desc(sixes),desc(fours))
details <- select(details,batsman,ballsPlayed,fours,sixes,runs,SR)
x_lower <- quantile(details$runs,p=0.66, na.rm = TRUE)
y_lower <- quantile(details$SR,p=0.66, na.rm = TRUE)
plot.title <- paste("Runs vs SR of ", t1, "in all matches against", t2)
if(plot == 1){ #ggplot2
details %>%
mutate(quadrant = case_when(runs > x_lower & SR > y_lower ~ "Q1",
runs <= x_lower & SR > y_lower ~ "Q2",
runs <= x_lower & SR <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SR,color=quadrant)) +
geom_text(aes(runs,SR,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs") + ylab("Strike rate") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- details %>%
mutate(quadrant = case_when(runs > x_lower & SR > y_lower ~ "Q1",
runs <= x_lower & SR > y_lower ~ "Q2",
runs <= x_lower & SR <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SR,color=quadrant)) +
geom_text(aes(runs,SR,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs") + ylab("Strike rate") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamRunsSRPlotOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 26 Nov 2021
# Function: teamRunsSRPowerPlayPlotAllOppnAllMatches
# This function plot the runs vs SR for the team batsman during powerplay against all opposition in
# in all matches
#
#
###########################################################################################
#' @title
#' Team batting plots runs vs SR in powerplay for team against all oppositions in all matches
#'
#' @description
#' This function computes and plots runs vs SR in power play of a team in all matches against all
#' oppositions.
#'
#' @usage
#' teamRunsSRPowerPlayPlotAllOppnAllMatches(matches,t1,plot=1)
#'
#' @param matches
#' All matches of the team in all matches with all oppositions
#'
#' @param t1
#' The team for which the the batting partnerships are sought
#'
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Top batsman is displayed in descending order of runs
#' teamRunsSRPowerPlayPlotAllOppnAllMatches(matches,t1,plot=1)
#'
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBowlingWicketRunsAllOppnAllMatches}}
#'
#' @export
#'
teamRunsSRPowerPlayPlotAllOppnAllMatches <- function(matches,t1,plot=1) {
team=ball=totalRuns=total=str_extract=batsman=runs=quantile=quadrant=SRPowerPlay=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team==t1)
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,ball,totalRuns,batsman,date)
a3 <- a2 %>% group_by(batsman) %>% summarise(runs=sum(totalRuns),count=n(), SRPowerPlay=runs/count*100)
x_lower <- quantile(a3$runs,p=0.66, na.rm = TRUE)
y_lower <- quantile(a3$SRPowerPlay,p=0.66, na.rm = TRUE)
plot.title <- paste(t1, " Runs vs SR in Power play in all matches against all opposition")
if(plot == 1){ #ggplot2
a3 %>%
mutate(quadrant = case_when(runs > x_lower & SRPowerPlay > y_lower ~ "Q1",
runs <= x_lower & SRPowerPlay > y_lower ~ "Q2",
runs <= x_lower & SRPowerPlay <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SRPowerPlay,color=quadrant)) +
geom_text(aes(runs,SRPowerPlay,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs - Power play") + ylab("Strike rate - Power play") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- a3 %>%
mutate(quadrant = case_when(runs > x_lower & SRPowerPlay > y_lower ~ "Q1",
runs <= x_lower & SRPowerPlay > y_lower ~ "Q2",
runs <= x_lower & SRPowerPlay <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SRPowerPlay,color=quadrant)) +
geom_text(aes(runs,SRPowerPlay,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs - Power play") + ylab("Strike rate - Power play") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamRunsSRPowerPlayPlotAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 26 Nov 2021
# Function: teamRunsSRPowerPlayPlotMatch
# This function plot the runs vs SR for the team batsman during powerplay against opposition in match
#
#
###########################################################################################
#' @title
#' Team batting plots runs vs SR in powerplay for team in match
#'
#' @description
#' This function computes and plots runs vs SR in power play of a team in match against
#' opposition.
#'
#' @usage
#' teamRunsSRPowerPlayPlotMatch(match,t1, t2, plot=1)
#'
#' @param match
#' Match
#'
#' @param t1
#' The team
#'
#' @param t2
#' The opposition team
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#'
#' # Top batsman is displayed in descending order of runs
#' teamRunsSRPowerPlayPlotMatch(match,t1="India",t2="England")
#'
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBowlingWicketRunsAllOppnAllMatches}}
#'
#' @export
#'
teamRunsSRPowerPlayPlotMatch <- function(match,t1,t2, plot=1) {
team=ball=totalRuns=total=str_extract=batsman=runs=quantile=quadrant=SRPowerPlay=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(match,team==t1)
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,ball,totalRuns,batsman,date)
a3 <- a2 %>% group_by(batsman) %>% summarise(runs=sum(totalRuns),count=n(), SRPowerPlay=runs/count*100)
x_lower <- quantile(a3$runs,p=0.66,na.rm = TRUE)
y_lower <- quantile(a3$SRPowerPlay,p=0.66,na.rm = TRUE)
plot.title <- paste(t1, " Runs vs SR in Power play against ", t2,sep="")
if(plot == 1){ #ggplot2
a3 %>%
mutate(quadrant = case_when(runs > x_lower & SRPowerPlay > y_lower ~ "Q1",
runs <= x_lower & SRPowerPlay > y_lower ~ "Q2",
runs <= x_lower & SRPowerPlay <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SRPowerPlay,color=quadrant)) +
geom_text(aes(runs,SRPowerPlay,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs - Power play") + ylab("Strike rate - Power play") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- a3 %>%
mutate(quadrant = case_when(runs > x_lower & SRPowerPlay > y_lower ~ "Q1",
runs <= x_lower & SRPowerPlay > y_lower ~ "Q2",
runs <= x_lower & SRPowerPlay <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SRPowerPlay,color=quadrant)) +
geom_text(aes(runs,SRPowerPlay,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs - Power play") + ylab("Strike rate - Power play") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamRunsSRPowerPlayPlotMatch.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 26 Nov 2021
# Function: teamRunsSRPowerPlayPlotOppnAllMatches
# This function plot the runs vs SR for the team batsman during powerplay against opposition in
# in all matches
#
#
###########################################################################################
#' @title
#' Team batting plots runs vs SR in powerplay for team against opposition in all matches
#'
#' @description
#' This function computes and plots runs vs SR in power play of a team in all matches against
#' opposition.
#'
#' @usage
#' teamRunsSRPowerPlayPlotOppnAllMatches(matches,t1, t2, plot=1)
#'
#' @param matches
#' All matches of the team in all matches with all oppositions
#'
#' @param t1
#' The team
#'
#' @param t2
#' The opposition team
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#'
#' # Top batsman is displayed in descending order of runs
#' teamRunsSRPowerPlayPlotOppnAllMatches(matches,t1="India")
#'
#' }
#'
#' @seealso
#' \code{\link{teamBatsmenVsBowlersAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBatsmenPartnershipOppnAllMatchesChart}}\cr
#' \code{\link{teamBatsmenPartnershipAllOppnAllMatchesPlot}}\cr
#' \code{\link{teamBowlingWicketRunsAllOppnAllMatches}}
#'
#' @export
#'
teamRunsSRPowerPlayPlotOppnAllMatches <- function(matches,t1,t2,plot=1) {
team=ball=totalRuns=total=str_extract=batsman=runs=quantile=quadrant=SRPowerPlay=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team==t1)
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,ball,totalRuns,batsman,date)
a3 <- a2 %>% group_by(batsman) %>% summarise(runs=sum(totalRuns),count=n(), SRPowerPlay=runs/count*100)
x_lower <- quantile(a3$runs,p=0.66,na.rm = TRUE)
y_lower <- quantile(a3$SRPowerPlay,p=0.66,na.rm = TRUE)
plot.title <- paste(t1, " Runs vs SR in Powerplay in all matches against ",t2)
if(plot == 1){ #ggplot2
a3 %>%
mutate(quadrant = case_when(runs > x_lower & SRPowerPlay > y_lower ~ "Q1",
runs <= x_lower & SRPowerPlay > y_lower ~ "Q2",
runs <= x_lower & SRPowerPlay <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SRPowerPlay,color=quadrant)) +
geom_text(aes(runs,SRPowerPlay,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs - Power play") + ylab("Strike rate - Power play") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- a3 %>%
mutate(quadrant = case_when(runs > x_lower & SRPowerPlay > y_lower ~ "Q1",
runs <= x_lower & SRPowerPlay > y_lower ~ "Q2",
runs <= x_lower & SRPowerPlay <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(runs,SRPowerPlay,color=quadrant)) +
geom_text(aes(runs,SRPowerPlay,label=batsman,color=quadrant)) + geom_point() +
xlab("Runs - Power play") + ylab("Strike rate - Power play") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamRunsSRPowerPlayPlotOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 4 Nov 2021
# Function: teamSRAcrossOvers
# This function the computes the Strike Rate in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the Strike Rate in powerplay, middle and death overs
#'
#' @description
#' This function plots strike rate scored in powerplay, middle and death overs
#'
#' @usage
#' teamSRAcrossOvers(match,t1,t2,plot=1)
#'
#' @param match
#' The dataframe of the match
#'
#' @param t1
#' The 1st team of the match
#'
#' @param t2
#' the 2nd team in the match
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Plot tne match worm plot
#' teamSRAcrossOvers(match,'England',"Pakistan")
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
teamSRAcrossOvers <- function(match,t1,t2,plot=1) {
team=ball=totalRuns=total=type=SR=str_extract=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(match,team ==t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,team,totalRuns)
a3 <- a2 %>% group_by(team) %>% summarise(total=sum(totalRuns),count=n())
a3$SR=ifelse(dim(a3)[1]==0, 0,a3$total/a3$count *100)
if(dim(a3)[1]!=0)
a3$type="1-Power Play"
# Middle overs I
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,team,totalRuns)
b3 <- b2 %>% group_by(team) %>% summarise(total=sum(totalRuns),count=n())
b3$SR=ifelse(dim(b3)[1]==0, 0,b3$total/b3$count *100)
if(dim(b3)[1]!=0)
b3$type="2-Middle Overs"
##Death overs
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,team,totalRuns)
c3 <- c2 %>% group_by(team) %>% summarise(total=sum(totalRuns),count=n())
c3$SR=ifelse(dim(c3)[1]==0, 0,c3$total/c3$count *100)
if(dim(c3)[1]!=0)
c3$type="3-Death Overs"
####################
# Filter the performance of team2
a <-filter(match,team ==t2)
# Power play
a11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a21 <- select(a11,team,totalRuns)
a31 <- a21 %>% group_by(team) %>% summarise(total=sum(totalRuns),count=n())
a31$SR=ifelse(dim(a31)[1]==0, 0,a31$total/a31$count *100)
if(dim(a31)[1]!=0)
a31$type="1-Power Play"
# Middle overs I
b11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b21 <- select(b11,team,totalRuns)
b31 <- b21 %>% group_by(team) %>% summarise(total=sum(totalRuns),count=n())
b31$SR=ifelse(dim(b31)[1]==0, 0,b31$total/b31$count *100)
if(dim(b31)[1]!=0)
b31$type="2-Middle Overs"
##Death overs
c11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c21 <- select(c11,team,totalRuns)
c31 <- c21 %>% group_by(team) %>% summarise(total=sum(totalRuns),count=n())
c31$SR=ifelse(dim(c31)[1]==0, 0,c31$total/c31$count *100)
if(dim(c31)[1]!=0)
c31$type="3-Death Overs"
m=rbind(a3,b3,c3,a31,b31,c31)
plot.title= paste("Strike rate across 20 overs of ",t1, "and", t2, sep=" ")
# Plot both lines
if(plot ==1){ #ggplot2
ggplot(m,aes(x=type, y=SR, fill=team)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),""))))
}else { #ggplotly
g <- ggplot(data = m,mapping=aes(x=type, y=SR, fill=team)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamSRAcrossOvers.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 5 Nov 2021
# Function: teamSRAcrossOversAllOppnAllMatches
# This function computes strike rate across overs in all matches against allopposition in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the strike rate by team against all team in powerplay, middle and death overs in all matches
#'
#' @description
#' This function plots the SR by team against all team in in powerplay, middle and death overs
#'
#' @usage
#' teamSRAcrossOversAllOppnAllMatches(matches,t1,plot=1)
#'
#' @param matches
#' The dataframe of the matches
#'
#' @param t1
#' The team of the matches
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Plot tne match worm plot
#' teamSRAcrossOversAllOppnAllMatches(matches,"Pakistan")
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
teamSRAcrossOversAllOppnAllMatches <- function(matches,t1,plot=1) {
team=ball=totalRuns=total=type=SR=meanSR=str_extract=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team==t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,team, totalRuns,date)
a3 <- a2 %>% group_by(team,date) %>% summarise(total=sum(totalRuns),count=n())
a3$SR = a3$total/a3$count *100
a4 = a3 %>% select(team,SR) %>% summarise(meanSR=mean(SR))
a4$type="1-Power Play"
# Middle overs I
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,team, totalRuns,date)
b3 <- b2 %>% group_by(team,date) %>% summarise(total=sum(totalRuns),count=n())
b3$SR = b3$total/b3$count *100
b4 = b3 %>% select(team,SR) %>% summarise(meanSR=mean(SR))
b4$type="2-Middle Overs"
#Death overs 2
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,team, totalRuns,date)
c3 <- c2 %>% group_by(team,date) %>% summarise(total=sum(totalRuns),count=n())
c3$SR = c3$total/c3$count *100
c4 = c3 %>% select(team,SR) %>% summarise(meanSR=mean(SR))
c4$type="3-Death Overs"
m=rbind(a4,b4,c4)
plot.title= paste("Strike rate across 20 overs by ",t1, "in all matches against all teams", sep=" ")
# Plot both lines
if(plot ==1){ #ggplot2
ggplot(data = m,mapping=aes(x=type, y=meanSR, fill=team)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),""))))
}else { #ggplotly
g <-ggplot(data = m,mapping=aes(x=type, y=meanSR, fill=team)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamSRAcrossOversAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 4 Nov 2021
# Function: teamSRAcrossOversOppnAllMatches
# This function computes strike rate across overs in all matches against opposition in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the strike rate by team against team in powerplay, middle and death overs in all matches
#'
#' @description
#' This function plots the SR by team against team in in powerplay, middle and death overs
#'
#' @usage
#' teamSRAcrossOversOppnAllMatches(matches,t1,t2,plot=1)
#'
#' @param matches
#' The dataframe of the matches
#'
#' @param t1
#' The 1st team of the match
#'
#' @param t2
#' the 2nd team in the match
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Plot tne match worm plot
#' teamSRAcrossOversOppnAllMatches(matches,'England',"Pakistan")
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
teamSRAcrossOversOppnAllMatches <- function(matches,t1,t2,plot=1) {
team=ball=totalRuns=total=type=SR=meanSR=str_extract=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team==t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,team, totalRuns,date)
a3 <- a2 %>% group_by(team,date) %>% summarise(total=sum(totalRuns),count=n())
a3$SR = a3$total/a3$count *100
a4 = a3 %>% select(team,SR) %>% summarise(meanSR=mean(SR))
a4$type="1-Power Play"
# Middle overs I
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,team, totalRuns,date)
b3 <- b2 %>% group_by(team,date) %>% summarise(total=sum(totalRuns),count=n())
b3$SR = b3$total/b3$count *100
b4 = b3 %>% select(team,SR) %>% summarise(meanSR=mean(SR))
b4$type="2-Middle Overs"
#Death overs 2
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,team, totalRuns,date)
c3 <- c2 %>% group_by(team,date) %>% summarise(total=sum(totalRuns),count=n())
c3$SR = c3$total/c3$count *100
c4 = c3 %>% select(team,SR) %>% summarise(meanSR=mean(SR))
c4$type="3-Death Overs"
####################
# Filter the performance of team2
a <-filter(matches,team==t2)
# Power play
a11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a21 <- select(a11,team, totalRuns,date)
a31 <- a21 %>% group_by(team,date) %>% summarise(total=sum(totalRuns),count=n())
a31$SR = a31$total/a31$count *100
a41 = a31 %>% select(team,SR) %>% summarise(meanSR=mean(SR))
a41$type="1-Power Play"
# Middle overs I
b11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 11.9))
b21 <- select(b11,team, totalRuns,date)
b31 <- b21 %>% group_by(team,date) %>% summarise(total=sum(totalRuns),count=n())
b31$SR = b31$total/b31$count *100
b41 = b31 %>% select(team,SR) %>% summarise(meanSR=mean(SR))
b41$type="2-Middle Overs"
#Death overs 2
c11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c21 <- select(c11,team, totalRuns,date)
c31 <- c21 %>% group_by(team,date) %>% summarise(total=sum(totalRuns),count=n())
c31$SR = c31$total/c31$count *100
c41 = c31 %>% select(team,SR) %>% summarise(meanSR=mean(SR))
c41$type="3-Death Overs"
m=rbind(a4,b4,c4,a41,b41,c41)
plot.title= paste("Strike rate across 20 overs by ",t1, "and", t2, "in all matches", sep=" ")
# Plot both lines
if(plot ==1){ #ggplot2
ggplot(data = m,mapping=aes(x=type, y=meanSR, fill=team)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),""))))
}else { #ggplotly
g <-ggplot(data = m,mapping=aes(x=type, y=meanSR, fill=team)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamSRAcrossOversOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 4 Nov 2021
# Function: teamWicketsAcrossOvers
# This function the computes the wickets taken in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the wickets in powerplay, middle and death overs
#'
#' @description
#' This function plots wickets scored in powerplay, middle and death overs
#'
#' @usage
#' teamWicketsAcrossOvers(match,t1,t2,plot=1)
#'
#' @param match
#' The dataframe of the match
#'
#' @param t1
#' The 1st team of the match
#'
#' @param t2
#' the 2nd team in the match
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Plot tne match worm plot
#' teamWicketsAcrossOvers(match,'England',"Pakistan")
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
teamWicketsAcrossOvers <- function(match,t1,t2,plot=1) {
team=ball=totalRuns=total=wicketPlayerOut=wickets=type=opposition=str_extract=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(match,team==t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,team,wicketPlayerOut)
a3 <- a2 %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
a3wickets=ifelse(!is.na(a3$wickets[1]), a3$wickets[1], 0)
if(!is.na(a3$wickets[1])){
a3$opposition=t2
a3$type="1-Power Play"
}
# Middle overs I
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,team,wicketPlayerOut)
b3 <- b2 %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
b3wickets=ifelse(!is.na(b3$wickets[1]), b3$wickets[1], 0)
if(!is.na(b3$wickets[1])){
b3$opposition=t2
b3$type="2-Middle Overs"
}
#Midle overs 2
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,team,wicketPlayerOut)
c3 <- c2 %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
c3wickets=ifelse(!is.na(c3$wickets[1]), c3$wickets[1], 0)
if(!is.na(c3$wickets[1])){
c3$opposition=t2
c3$type="3-Death Overs"
}
####################
# Filter the performance of team2
a <-filter(match,team==t2)
# Power play
a11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a21 <- select(a11,team,wicketPlayerOut)
a31 <- a21 %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
a31wickets=ifelse(!is.na(a31$wickets[1]), a31$wickets[1], 0)
if(!is.na(a31$wickets[1])){
a31$opposition=t1
a31$type="1-Power Play"
}
b11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b21 <- select(b11,team,wicketPlayerOut)
b31 <- b21 %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
b31wickets=ifelse(!is.na(b31$wickets[1]), b31$wickets[1], 0)
if(!is.na(b31$wickets[1])){
b31$type="2-Middle Overs"
b31$opposition=t1
}
#Midle overs 2
c11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c21 <- select(c11,team,wicketPlayerOut)
c31 <- c21 %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
c31wickets=ifelse(!is.na(c31$wickets[1]), c31$wickets[1], 0)
if(!is.na(c31$wickets[1])){
c31$opposition=t1
c31$type="3-Death Overs"
}
m=rbind(a3,b3,c3,a31,b31,c31)
plot.title= paste("Wickets across 20 overs of ",t1, "and", t2, sep=" ")
# Plot both lines
if(plot ==1){ #ggplot2
plot.title= paste("Wickets across 20 overs of ",t1, "and", t2, sep=" ")
ggplot(m,aes(x=type, y=wickets, fill=opposition)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),""))))
}else { #ggplotly
g <- ggplot(m,aes(x=type, y=wickets, fill=opposition)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamWicketsAcrossOvers.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 5 Nov 2021
# Function: teamWicketsAcrossOversAllOppnAllMatches.R
# This function computes wickets across overs in all matches against all opposition in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the wickets by team against all team in powerplay, middle and death overs in all matches
#'
#' @description
#' This function plots the wickets by team against all team in in powerplay, middle and death overs
#'
#' @usage
#' teamWicketsAcrossOversAllOppnAllMatches(matches,t1,plot=1)
#'
#' @param matches
#' The dataframe of the matches
#'
#' @param t1
#' The 1st team of the match
#'
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Plot tne match worm plot
#' teamWicketsAcrossOversAllOppnAllMatches(matches,t1,plot=1)
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
teamWicketsAcrossOversAllOppnAllMatches <- function(matches,t1,plot=1) {
team=ball=totalRuns=total=wicketPlayerOut=meanWickets=type=opposition=str_extract=t2=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team==t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,team,date,wicketPlayerOut)
a3 <- a2 %>% group_by(team,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(count =n())
a4 = select(a3,team,count) %>% group_by(team) %>% summarise(meanWickets=mean(count))
a4$opposition=t1
a4$type="1-Power Play"
# Middle overs
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,team,date,wicketPlayerOut)
b3 <- b2 %>% group_by(team,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(count =n())
b4 = select(b3,team,count) %>% group_by(team) %>% summarise(meanWickets=mean(count))
b4$opposition=t1
b4$type="2-Middle Overs"
#Death overs
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,team,date,wicketPlayerOut)
c3 <- c2 %>% group_by(team,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(count =n())
c4 = select(c3,team,count) %>% group_by(team) %>% summarise(meanWickets=mean(count))
c4$opposition=t1
c4$type="3-Death Overs"
m=rbind(a4,b4,c4)
plot.title= paste("Wickets across 20 overs by ",t1, "in all matches against all teams", sep=" ")
# Plot both lines
if(plot ==1){ #ggplot2
ggplot(m,aes(x=type, y=meanWickets, fill=opposition)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),""))))
}else { #ggplotly
g <- ggplot(m,aes(x=type, y=meanWickets, fill=opposition)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamWicketsAcrossOversAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 4 Nov 2021
# Function: teamWicketsAcrossOversOppnAllMatches.R
# This function computes wickets across overs in all matches against opposition in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the wickets by team against team in powerplay, middle and death overs in all matches
#'
#' @description
#' This function plots the wickets by team against team in in powerplay, middle and death overs
#'
#' @usage
#' teamWicketsAcrossOversOppnAllMatches(matches,t1,t2,plot=1)
#'
#' @param matches
#' The dataframe of the matches
#'
#' @param t1
#' The 1st team of the match
#'
#' @param t2
#' the 2nd team in the match
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Plot tne match worm plot
#' teamWicketsAcrossOversOppnAllMatches.R(matches,'England',"Pakistan")
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
teamWicketsAcrossOversOppnAllMatches <- function(matches,t1,t2,plot=1) {
team=ball=totalRuns=total=wicketPlayerOut=meanWickets=type=count=opposition=str_extract=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team==t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,team,date,wicketPlayerOut)
a3 <- a2 %>% group_by(team,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(count =n())
a4 = select(a3,team,count) %>% group_by(team) %>% summarise(meanWickets=mean(count))
a4$opposition=t2
a4$type="1-Power Play"
# Middle overs
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,team,date,wicketPlayerOut)
b3 <- b2 %>% group_by(team,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(count =n())
b4 = select(b3,team,count) %>% group_by(team) %>% summarise(meanWickets=mean(count))
b4$opposition=t2
b4$type="2-Middle Overs"
#Death overs
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,team,date,wicketPlayerOut)
c3 <- c2 %>% group_by(team,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(count =n())
c4 = select(c3,team,count) %>% group_by(team) %>% summarise(meanWickets=mean(count))
c4$opposition=t2
c4$type="3-Death Overs"
####################
# Filter the performance of team2
a <-filter(matches,team==t2)
# Power play
a11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a21 <- select(a11,team,date,wicketPlayerOut)
a31 <- a21 %>% group_by(team,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(count =n())
a41 = select(a31,team,count) %>% group_by(team) %>% summarise(meanWickets=mean(count))
a41$opposition=t1
a41$type="1-Power Play"
# Middle overs I
b11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b21 <- select(b11,team,date,wicketPlayerOut)
b31 <- b21 %>% group_by(team,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(count =n())
b41 = select(b31,team,count) %>% group_by(team) %>% summarise(meanWickets=mean(count))
b41$opposition=t1
b41$type="2-Middle Overs"
#Midle overs 2
c11 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 12.1, 16.9))
c21 <- select(c11,team,date,wicketPlayerOut)
c31 <- c21 %>% group_by(team,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(count =n())
c41 = select(c31,team,count) %>% group_by(team) %>% summarise(meanWickets=mean(count))
c41$opposition=t1
c41$type="3-Death Overs"
m=rbind(a4,b4,c4,a41,b41,c41)
plot.title= paste("Wickets across 20 overs by ",t1, "and", t2, "in all matches", sep=" ")
# Plot both lines
if(plot ==1){ #ggplot2
ggplot(m,aes(x=type, y=meanWickets, fill=opposition)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(bquote(atop(.(plot.title),
atop(italic("Data source:http://cricsheet.org/"),""))))
}else { #ggplotly
g <- ggplot(m,aes(x=type, y=meanWickets, fill=opposition)) +
geom_bar(stat="identity", position = "dodge") +
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamWicketsAcrossOversOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 27 Nov 2021
# Function: teamWicketsERDeathOversPlotAllOppnAllMatches
# This function computes the wickets vs ER of team in death overs against all opposition in all matches
#
###########################################################################################
#' @title
#' Team wickets vs ER in death overs against all opposition all matches
#'
#' @description
#' This function computes wickets vs ER in death overs against all oppositions in all matches
#'
#' @usage
#' teamWicketsERDeathOversPlotAllOppnAllMatches(matches,t1, plot=1)
#'
#' @param matches
#' The matches of the team against all oppositions and all matches
#'
#' @param t1
#' Team for which bowling performance is required
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' teamWicketsERDeathOversPlotAllOppnAllMatches(matches, t1, plot=1)
#'
#'}
#' @seealso
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesMain}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamWicketsERDeathOversPlotAllOppnAllMatches <- function(matches,t1,plot=1) {
team=ball=totalRuns=total=wickets=wicketsPowerPlay=wicketsDeathOvers=wicketsDeathOvers=bowler=str_extract=NULL
ggplotly=wicketPlayerOut=str_extract=quantile=quadrant=ERDeathOvers=NULL
# Filter the performance of team1
a <-filter(matches,team!=t1)
# Middle overs
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
a2 <- select(a1,date,bowler,wicketPlayerOut)
a3 <- a2 %>% group_by(bowler,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
a4 <- a3 %>% select(date,bowler,wickets) %>% distinct(date,bowler,wickets) %>% group_by(bowler) %>% summarise(wicketsDeathOvers=sum(wickets))
a21 <- select(a1,team,bowler,date,totalRuns)
a31 <- a21 %>% group_by(bowler) %>% summarise(total=sum(totalRuns),count=n(), ERDeathOvers=total/count *6)
a41 <- a31 %>% select(bowler,ERDeathOvers)
a42=inner_join(a4,a41,by="bowler")
x_lower <- quantile(a42$wicketsDeathOvers,p=0.66,na.rm = TRUE)
y_lower <- quantile(a42$ERDeathOvers,p=0.66,na.rm = TRUE)
plot.title <- paste("Wickets-ER in death overs of", t1, "against all opposition all matches")
if(plot == 1){ #ggplot2
a42 %>%
mutate(quadrant = case_when(wicketsDeathOvers > x_lower & ERDeathOvers > y_lower ~ "Q1",
wicketsDeathOvers <= x_lower & ERDeathOvers > y_lower ~ "Q2",
wicketsDeathOvers <= x_lower & ERDeathOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wicketsDeathOvers,ERDeathOvers,color=quadrant)) +
geom_text(aes(wicketsDeathOvers,ERDeathOvers,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets - Death overs") + ylab("Economy rate - Death overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- a42 %>%
mutate(quadrant = case_when(wicketsDeathOvers > x_lower & ERDeathOvers > y_lower ~ "Q1",
wicketsDeathOvers <= x_lower & ERDeathOvers > y_lower ~ "Q2",
wicketsDeathOvers <= x_lower & ERDeathOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wicketsDeathOvers,ERDeathOvers,color=quadrant)) +
geom_text(aes(wicketsDeathOvers,ERDeathOvers,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets - Death overs") + ylab("Economy rate - Death overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamWicketsERDeathOversPlotAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 27 Nov 2021
# Function: teamWicketsERDeathOversPlotMatch
# This function computes the wickets vs ER of team in death overs against opposition in match
#
###########################################################################################
#' @title
#' Team wickets vs ER in death overs against opposition in match
#'
#' @description
#' This function computes wickets vs ER in death overs against oppositions in match
#'
#' @usage
#' teamWicketsERDeathOversPlotMatch(match,t1, t2, plot=1)
#'
#' @param match
#' The match of the team against opposition
#'
#' @param t1
#' Team for which bowling performance is required
#'
#' @param t2
#' Opposition Team
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' teamWicketsERDeathOversPlotMatch(match,t1,t2,plot=1)
#'}
#' @seealso
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesMain}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamWicketsERDeathOversPlotMatch <- function(match,t1,t2,plot=1) {
team=ball=totalRuns=total=wickets=wicketsPowerPlay=wicketsDeathOvers=wicketsDeathOvers=bowler=str_extract=NULL
ggplotly=wicketPlayerOut=str_extract=quantile=quadrant=ERDeathOvers=NULL
# Filter the performance of team1
a <-filter(match,team!=t1)
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
a2 <- select(a1,date,bowler,wicketPlayerOut)
a3 <- a2 %>% group_by(bowler,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
a4 <- a3 %>% select(date,bowler,wickets) %>% distinct(date,bowler,wickets) %>% group_by(bowler) %>% summarise(wicketsDeathOvers=sum(wickets))
a21 <- select(a1,team,bowler,date,totalRuns)
a31 <- a21 %>% group_by(bowler) %>% summarise(total=sum(totalRuns),count=n(), ERDeathOvers=total/count *6)
a41 <- a31 %>% select(bowler,ERDeathOvers)
a42=inner_join(a4,a41,by="bowler")
x_lower <- quantile(a42$wicketsDeathOvers,p=0.66,na.rm = TRUE)
y_lower <- quantile(a42$ERDeathOvers,p=0.33,na.rm = TRUE)
plot.title <- paste("Wickets-ER in Death overs of ", t1, " against ", t2, " in death overs")
if(plot == 1){ #ggplot2
a42 %>%
mutate(quadrant = case_when(wicketsDeathOvers > x_lower & ERDeathOvers > y_lower ~ "Q1",
wicketsDeathOvers <= x_lower & ERDeathOvers > y_lower ~ "Q2",
wicketsDeathOvers <= x_lower & ERDeathOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wicketsDeathOvers,ERDeathOvers,color=quadrant)) +
geom_text(aes(wicketsDeathOvers,ERDeathOvers,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets - Death overs") + ylab("Economy rate - Death overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- a42 %>%
mutate(quadrant = case_when(wicketsDeathOvers > x_lower & ERDeathOvers > y_lower ~ "Q1",
wicketsDeathOvers <= x_lower & ERDeathOvers > y_lower ~ "Q2",
wicketsDeathOvers <= x_lower & ERDeathOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wicketsDeathOvers,ERDeathOvers,color=quadrant)) +
geom_text(aes(wicketsDeathOvers,ERDeathOvers,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets - Death overs") + ylab("Economy rate - Death overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamWicketsERDeathOversPlotMatch.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 27 Nov 2021
# Function: teamWicketERDeathOversPlotOppnAllMatches
# This function computes the wickets vs ER of team in death overs against opposition in all matches
#
###########################################################################################
#' @title
#' Team wickets vs ER in death overs against opposition all matches
#'
#' @description
#' This function computes wickets vs ER in death overs against oppositions in all matches
#'
#' @usage
#' teamWicketERDeathOversPlotOppnAllMatches(matches,t1,t2,plot=1)
#'
#' @param matches
#' The matches of the team against all oppositions and all matches
#'
#' @param t1
#' Team for which bowling performance is required
#'
#' @param t2
#' Opposition Team
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' teamWicketERDeathOversPlotOppnAllMatches(matches,t1,t2,plot=1)
#'}
#' @seealso
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesMain}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamWicketERDeathOversPlotOppnAllMatches <- function(matches,t1,t2,plot=1) {
team=ball=totalRuns=total=wickets=wicketsPowerPlay=wicketsDeathOvers=wicketsDeathOvers=bowler=str_extract=NULL
ggplotly=wicketPlayerOut=str_extract=quantile=quadrant=ERDeathOvers=NULL
# Filter the performance of team1
a <-filter(matches,team!=t1)
# Middle overs
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
a2 <- select(a1,date,bowler,wicketPlayerOut)
a3 <- a2 %>% group_by(bowler,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
a4 <- a3 %>% select(date,bowler,wickets) %>% distinct(date,bowler,wickets) %>% group_by(bowler) %>% summarise(wicketsDeathOvers=sum(wickets))
a21 <- select(a1,team,bowler,date,totalRuns)
a31 <- a21 %>% group_by(bowler) %>% summarise(total=sum(totalRuns),count=n(), ERDeathOvers=total/count *6)
a41 <- a31 %>% select(bowler,ERDeathOvers)
a42=inner_join(a4,a41,by="bowler")
x_lower <- quantile(a42$wicketsDeathOvers,p=0.66,na.rm = TRUE)
y_lower <- quantile(a42$ERDeathOvers,p=0.33,na.rm = TRUE)
plot.title <- paste("Wickets-ER in Death overs of", t1, " against ", t2, " in all matches")
if(plot == 1){ #ggplot2
a42 %>%
mutate(quadrant = case_when(wicketsDeathOvers > x_lower & ERDeathOvers > y_lower ~ "Q1",
wicketsDeathOvers <= x_lower & ERDeathOvers > y_lower ~ "Q2",
wicketsDeathOvers <= x_lower & ERDeathOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wicketsDeathOvers,ERDeathOvers,color=quadrant)) +
geom_text(aes(wicketsDeathOvers,ERDeathOvers,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets - Death overs") + ylab("Economy rate - Death overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- a42 %>%
mutate(quadrant = case_when(wicketsDeathOvers > x_lower & ERDeathOvers > y_lower ~ "Q1",
wicketsDeathOvers <= x_lower & ERDeathOvers > y_lower ~ "Q2",
wicketsDeathOvers <= x_lower & ERDeathOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wicketsDeathOvers,ERDeathOvers,color=quadrant)) +
geom_text(aes(wicketsDeathOvers,ERDeathOvers,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets - Death overs") + ylab("Economy rate - Death overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamWicketsERDeathOversPlotOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 27 Nov 2021
# Function: teamWicketERMiddleOversPlotAllOppnAllMatches
# This function computes the wickets vs ER of team in middle overs against all opposition in all matches
#
###########################################################################################
#' @title
#' Team wickets vs ER in middle overs against all opposition all matches
#'
#' @description
#' This function computes wickets vs ER in middle overs against all oppositions in all matches
#'
#' @usage
#' teamWicketERMiddleOversPlotAllOppnAllMatches(matches,t1, plot=1)
#'
#' @param matches
#' The matches of the team against all oppositions and all matches
#'
#' @param t1
#' Team for which bowling performance is required
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' teamWicketERMiddleOversPlotAllOppnAllMatches(matches, t1, plot=1)
#' }
#' @seealso
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesMain}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamWicketERMiddleOversPlotAllOppnAllMatches <- function(matches,t1, plot=1) {
team=ball=totalRuns=total=wickets=wicketsMiddleOvers=wicketsDeathOvers=bowler=str_extract=NULL
ggplotly=wicketPlayerOut=str_extract=quantile=quadrant=ERMiddleOvers=NULL
# Filter the performance of team1
a <-filter(matches,team!=t1)
# Middle overs
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
a2 <- select(a1,date,bowler,wicketPlayerOut)
a3 <- a2 %>% group_by(bowler,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
a4 <- a3 %>% select(date,bowler,wickets) %>% distinct(date,bowler,wickets) %>% group_by(bowler) %>% summarise(wicketsMiddleOvers=sum(wickets))
a21 <- select(a1,team,bowler,date,totalRuns)
a31 <- a21 %>% group_by(bowler) %>% summarise(total=sum(totalRuns),count=n(), ERMiddleOvers=total/count *6)
a41 <- a31 %>% select(bowler,ERMiddleOvers)
a42=inner_join(a4,a41,by="bowler")
x_lower <- quantile(a42$wicketsMiddleOvers,p=0.66,na.rm = TRUE)
y_lower <- quantile(a42$ERMiddleOvers,p=0.33,na.rm = TRUE)
plot.title <- paste("Wickets-ER Plot of", t1, "in Middle overs against all opposition all matches")
if(plot == 1){ #ggplot2
a42 %>%
mutate(quadrant = case_when(wicketsMiddleOvers > x_lower & ERMiddleOvers > y_lower ~ "Q1",
wicketsMiddleOvers <= x_lower & ERMiddleOvers > y_lower ~ "Q2",
wicketsMiddleOvers <= x_lower & ERMiddleOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wicketsMiddleOvers,ERMiddleOvers,color=quadrant)) +
geom_text(aes(wicketsMiddleOvers,ERMiddleOvers,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets - Middle overs") + ylab("Economy rate - Middle overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- a42 %>%
mutate(quadrant = case_when(wicketsMiddleOvers > x_lower & ERMiddleOvers > y_lower ~ "Q1",
wicketsMiddleOvers <= x_lower & ERMiddleOvers > y_lower ~ "Q2",
wicketsMiddleOvers <= x_lower & ERMiddleOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wicketsMiddleOvers,ERMiddleOvers,color=quadrant)) +
geom_text(aes(wicketsMiddleOvers,ERMiddleOvers,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets - Middle overs") + ylab("Economy rate - Middle overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamWicketsERMiddleOversPlotAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 27 Nov 2021
# Function: teamWicketsERMiddleOversPlotMatch
# This function computes the wickets vs ER of team in middle overs against opposition in match
#
###########################################################################################
#' @title
#' Team wickets vs ER in middle overs against opposition in match
#'
#' @description
#' This function computes wickets vs ER in middle overs against oppositions in all match
#'
#' @usage
#' teamWicketsERMiddleOversPlotMatch(match,t1, t2, plot=1)
#'
#' @param match
#' The match of the team against opposition
#'
#' @param t1
#' Team for which bowling performance is required
#'
#' @param t2
#' Opposition Team
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' teamWicketsERMiddleOversPlotMatch(match, t1,t2, plot=1)
#'}
#' @seealso
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesMain}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamWicketsERMiddleOversPlotMatch <- function(match,t1,t2,plot=1) {
team=ball=totalRuns=total=wickets=wicketsPowerPlay=wicketsMiddleOvers=wicketsDeathOvers=bowler=str_extract=NULL
ggplotly=wicketPlayerOut=str_extract=quantile=quadrant=ERMiddleOvers=NULL
# Filter the performance of team1
a <-filter(match,team!=t1)
# Middle overs
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
a2 <- select(a1,date,bowler,wicketPlayerOut)
a3 <- a2 %>% group_by(bowler,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
a4 <- a3 %>% select(date,bowler,wickets) %>% distinct(date,bowler,wickets) %>% group_by(bowler) %>% summarise(wicketsMiddleOvers=sum(wickets))
a21 <- select(a1,team,bowler,date,totalRuns)
a31 <- a21 %>% group_by(bowler) %>% summarise(total=sum(totalRuns),count=n(), ERMiddleOvers=total/count *6)
a41 <- a31 %>% select(bowler,ERMiddleOvers)
a42=inner_join(a4,a41,by="bowler")
x_lower <- quantile(a42$wicketsMiddleOvers,p=0.66,na.rm = TRUE)
y_lower <- quantile(a42$ERMiddleOvers,p=0.66,na.rm = TRUE)
plot.title <- paste("Wickets-ER in Middle overs of ", t1, " against ", t2, " in middle overs")
if(plot == 1){ #ggplot2
a42 %>%
mutate(quadrant = case_when(wicketsMiddleOvers > x_lower & ERMiddleOvers > y_lower ~ "Q1",
wicketsMiddleOvers <= x_lower & ERMiddleOvers > y_lower ~ "Q2",
wicketsMiddleOvers <= x_lower & ERMiddleOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wicketsMiddleOvers,ERMiddleOvers,color=quadrant)) +
geom_text(aes(wicketsMiddleOvers,ERMiddleOvers,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets - Middle overs") + ylab("Economy rate - Middle overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- a42 %>%
mutate(quadrant = case_when(wicketsMiddleOvers > x_lower & ERMiddleOvers > y_lower ~ "Q1",
wicketsMiddleOvers <= x_lower & ERMiddleOvers > y_lower ~ "Q2",
wicketsMiddleOvers <= x_lower & ERMiddleOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wicketsMiddleOvers,ERMiddleOvers,color=quadrant)) +
geom_text(aes(wicketsMiddleOvers,ERMiddleOvers,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets - Middle overs") + ylab("Economy rate - Middle overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamWicketsERMiddleOversPlotMatch.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 27 Nov 2021
# Function: teamWicketERMiddleOversPlotOppnAllMatches
# This function computes the wickets vs ER of team in middle overs against opposition in all matches
#
###########################################################################################
#' @title
#' Team wickets vs ER in middle overs against a pposition all matches
#'
#' @description
#' This function computes wickets vs ER in middle overs against all oppositions in all matches
#'
#' @usage
#' teamWicketERMiddleOversPlotOppnAllMatches(matches,t1, t2, plot=1)
#'
#' @param matches
#' The matches of the team against all oppositions and all matches
#'
#' @param t1
#' Team for which bowling performance is required
#'
#' @param t2
#' Opposition Team
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' teamWicketERMiddleOversPlotOppnAllMatches(matches,t1,t2,plot=1)
#'}
#' @seealso
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesMain}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamWicketERMiddleOversPlotOppnAllMatches <- function(matches,t1,t2,plot=1) {
team=ball=totalRuns=total=wickets=wicketsPowerPlay=wicketsMiddleOvers=wicketsDeathOvers=bowler=str_extract=NULL
ggplotly=wicketPlayerOut=str_extract=quantile=quadrant=ERMiddleOvers=NULL
# Filter the performance of team1
a <-filter(matches,team!=t1)
# Middle overs
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
a2 <- select(a1,date,bowler,wicketPlayerOut)
a3 <- a2 %>% group_by(bowler,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
a4 <- a3 %>% select(date,bowler,wickets) %>% distinct(date,bowler,wickets) %>% group_by(bowler) %>% summarise(wicketsMiddleOvers=sum(wickets))
a21 <- select(a1,team,bowler,date,totalRuns)
a31 <- a21 %>% group_by(bowler) %>% summarise(total=sum(totalRuns),count=n(), ERMiddleOvers=total/count *6)
a41 <- a31 %>% select(bowler,ERMiddleOvers)
a42=inner_join(a4,a41,by="bowler")
x_lower <- quantile(a42$wicketsMiddleOvers,p=0.66,na.rm = TRUE)
y_lower <- quantile(a42$ERMiddleOvers,p=0.33,na.rm = TRUE)
plot.title <- paste("Wickets-ER in Middle overs of", t1, " against ", t2, "in all matches")
if(plot == 1){ #ggplot2
a42 %>%
mutate(quadrant = case_when(wicketsMiddleOvers > x_lower & ERMiddleOvers > y_lower ~ "Q1",
wicketsMiddleOvers <= x_lower & ERMiddleOvers > y_lower ~ "Q2",
wicketsMiddleOvers <= x_lower & ERMiddleOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wicketsMiddleOvers,ERMiddleOvers,color=quadrant)) +
geom_text(aes(wicketsMiddleOvers,ERMiddleOvers,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets - Middle overs") + ylab("Economy rate - Middle overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- a42 %>%
mutate(quadrant = case_when(wicketsMiddleOvers > x_lower & ERMiddleOvers > y_lower ~ "Q1",
wicketsMiddleOvers <= x_lower & ERMiddleOvers > y_lower ~ "Q2",
wicketsMiddleOvers <= x_lower & ERMiddleOvers <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wicketsMiddleOvers,ERMiddleOvers,color=quadrant)) +
geom_text(aes(wicketsMiddleOvers,ERMiddleOvers,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets - Middle overs") + ylab("Economy rate - Middle overs") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamWicketsERMiddleOversPlotOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 23 Nov 2021
# Function: teamWicketsERPlotAllOppnAllMatches
# This function computes the wickets vs ER of team against all opposition in all matches
#
###########################################################################################
#' @title
#' Team wickets vs ER against all opposition all matches
#'
#' @description
#' This function computes wickets vs ER against all oppositions in all matches
#'
#' @usage
#' teamWicketsERPlotAllOppnAllMatches(matches,theTeam, plot=1)
#'
#' @param matches
#' The matches of the team against all oppositions and all matches
#'
#' @param theTeam
#' Team for which bowling performance is required
#'
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' wicketsERAllOppnAllMatches
#'}
#' @seealso
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesMain}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamWicketsERPlotAllOppnAllMatches <- function(matches,theTeam,plot=1){
noBalls=wides=team=runs=bowler=wicketKind=wicketPlayerOut=ER=quantile=quadrant=NULL
team=bowler=ball=wides=noballs=runsConceded=overs=ggplotly=NULL
over=wickets=maidens=NULL
a <-filter(matches,team!=theTeam)
a1 <- unlist(strsplit(a$ball[1],"\\."))
# Create a string for substitution 1st or 2nd
a2 <- paste(a1[1],"\\.",sep="")
# only wides and noballs need to be included with runs for bowlers.
# Note: byes and legbyes should not be included
b <- a %>%
select(bowler,ball,noballs,wides,runs,wicketKind,wicketPlayerOut) %>%
#mutate(over=gsub("1st\\.","",ball)) %>%
mutate(over=gsub(a2,"",ball)) %>%
mutate(over=gsub("\\.\\d+","",over))
#Calculate the number of maiden overs
c <- summarise(group_by(b,bowler,over),sum(runs,wides,noballs))
names(c) <- c("bowler","over","runsConceded")
d <-summarize(group_by(c,bowler),maidens=sum(runsConceded==0))
#Compute total runs conceded (runs_wides+noballs)
e <- summarize(group_by(c,bowler),runs=sum(runsConceded))
# Calculate the number of overs bowled by each bwler
f <- select(c,bowler,over)
g <- summarise(group_by(f,bowler),overs=length(unique(over)))
#Compute number of wickets
h <- b %>%
select(bowler,wicketKind,wicketPlayerOut) %>%
filter(wicketPlayerOut != "nobody")
i <- summarise(group_by(h,bowler),wickets=length(wicketPlayerOut))
#Join the over & maidens
j <- full_join(g,d,by="bowler")
# Add runs
k <- full_join(j,e,by="bowler")
# Add wickets
l <- full_join(k,i,by="bowler")
# Set NAs to 0 if there are any
if(sum(is.na(l$wickets)) != 0){
l[is.na(l$wickets),]$wickets=0
}
# Arrange in descending order of wickets and runs and ascending order for maidens
l <-arrange(l,desc(wickets),desc(runs),maidens)
l$ER = l$runs/l$overs
x_lower <- quantile(l$wickets,p=0.66,na.rm = TRUE)
y_lower <- quantile(l$ER,p=0.66,na.rm = TRUE)
plot.title <- paste("Wickets-ER Plot of", theTeam, "against all opposition all matches")
if(plot == 1){ #ggplot2
l %>%
mutate(quadrant = case_when(wickets > x_lower & ER > y_lower ~ "Q1",
wickets <= x_lower & ER > y_lower ~ "Q2",
wickets <= x_lower & ER <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wickets,ER,color=quadrant)) +
geom_text(aes(wickets,ER,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets") + ylab("Economy rate") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- l %>%
mutate(quadrant = case_when(wickets > x_lower & ER > y_lower ~ "Q1",
wickets <= x_lower & ER > y_lower ~ "Q2",
wickets <= x_lower & ER <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wickets,ER,color=quadrant)) +
geom_text(aes(wickets,ER,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets") + ylab("Economy rate") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamWicketsERPlotAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 23 Nov 2021
# Function: teamWicketsERPlotMatch
# This function computes the wickets vs ER of team in match
#
###########################################################################################
#' @title
#' Team wickets vs ER against in match
#'
#' @description
#' This function computes wickets vs ER in match
#'
#' @usage
#' teamWicketsERPlotMatch(match,t1,t2,plot=1)
#'
#' @param match
#' The match of the team against opposition
#'
#' @param t1
#' The 1st team of the match
#'
#' @param t2
#' the 2nd team in the match
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' teamWicketsERPlotMatch(match,t1,t2,plot=1)
#'}
#' @seealso
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesMain}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamWicketsERPlotMatch <- function(match,t1,t2,plot=1){
noBalls=wides=team=runs=bowler=wicketKind=wicketPlayerOut=NULL
team=bowler=ball=wides=noballs=runsConceded=overs=NULL
over=wickets=maidens=str_extract=quantile=quadrant=ER=ggplotly=NULL
a <-filter(match,team!=t1)
a1 <- unlist(strsplit(a$ball[1],"\\."))
# Create a string for substitution 1st or 2nd
a2 <- paste(a1[1],"\\.",sep="")
# only wides and noballs need to be included with runs for bowlers.
# Note: byes and legbyes should not be included
b <- a %>%
select(bowler,ball,noballs,wides,runs,wicketKind,wicketPlayerOut) %>%
#mutate(over=gsub("1st\\.","",ball)) %>%
mutate(over=gsub(a2,"",ball)) %>%
mutate(over=gsub("\\.\\d+","",over))
#Calculate the number of maiden overs
c <- summarise(group_by(b,bowler,over),sum(runs,wides,noballs))
names(c) <- c("bowler","over","runsConceded")
d <-summarize(group_by(c,bowler),maidens=sum(runsConceded==0))
#Compute total runs conceded (runs_wides+noballs)
e <- summarize(group_by(c,bowler),runs=sum(runsConceded))
# Calculate the number of overs bowled by each bwler
f <- select(c,bowler,over)
g <- summarise(group_by(f,bowler),overs=length(unique(over)))
#Compute number of wickets
h <- b %>%
select(bowler,wicketKind,wicketPlayerOut) %>%
filter(wicketPlayerOut != "nobody")
i <- summarise(group_by(h,bowler),wickets=length(wicketPlayerOut))
#Join the over & maidens
j <- full_join(g,d,by="bowler")
# Add runs
k <- full_join(j,e,by="bowler")
# Add wickets
l <- full_join(k,i,by="bowler")
# Set NAs to 0 if there are any
if(sum(is.na(l$wickets)) != 0){
l[is.na(l$wickets),]$wickets=0
}
# Arrange in descending order of wickets and runs and ascending order for maidens
l <-arrange(l,desc(wickets),desc(runs),maidens)
l$ER = l$runs/l$overs
x_lower <- quantile(l$wickets,p=0.66,na.rm = TRUE)
y_lower <- quantile(l$ER,p=0.66,na.rm = TRUE)
plot.title <- paste("Wickets-ER Plot of", t1, "in match against ", t2)
if(plot == 1){ #ggplot2
l %>%
mutate(quadrant = case_when(wickets > x_lower & ER > y_lower ~ "Q1",
wickets <= x_lower & ER > y_lower ~ "Q2",
wickets <= x_lower & ER <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wickets,ER,color=quadrant)) +
geom_text(aes(wickets,ER,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets") + ylab("Economy rate") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- l %>%
mutate(quadrant = case_when(wickets > x_lower & ER > y_lower ~ "Q1",
wickets <= x_lower & ER > y_lower ~ "Q2",
wickets <= x_lower & ER <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wickets,ER,color=quadrant)) +
geom_text(aes(wickets,ER,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets") + ylab("Economy rate") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamWicketsERPlotMatch.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 23 Nov 2021
# Function: teamWicketsERPlotOppnAllMatches
# This function computes the wickets vs ER of team against all opposition in all matches
#
###########################################################################################
#' @title
#' Team wickets vs ER against all opposition all matches
#'
#' @description
#' This function computes wickets vs ER against all oppositions in all matches
#'
#' @usage
#' teamWicketsERPlotOppnAllMatches(matches,t1,t2,plot=1)
#'
#' @param matches
#' The matches of the team against all oppositions and all matches
#'
#' @param t1
#' The 1st team of the match
#'
#' @param t2
#' the 2nd team in the match
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' teamWicketsERPlotOppnAllMatches(matches,t1,t2,plot=1)
#'}
#' @seealso
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesMain}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamWicketsERPlotOppnAllMatches <- function(matches,t1,t2,plot=1){
noBalls=wides=team=runs=bowler=wicketKind=wicketPlayerOut=ER=quantile=quadrant=NULL
team=bowler=ball=wides=noballs=runsConceded=overs=ggplotly=NULL
over=wickets=maidens=NULL
a <-filter(matches,team!=t1)
a1 <- unlist(strsplit(a$ball[1],"\\."))
# Create a string for substitution 1st or 2nd
a2 <- paste(a1[1],"\\.",sep="")
# only wides and noballs need to be included with runs for bowlers.
# Note: byes and legbyes should not be included
b <- a %>%
select(bowler,ball,noballs,wides,runs,wicketKind,wicketPlayerOut) %>%
#mutate(over=gsub("1st\\.","",ball)) %>%
mutate(over=gsub(a2,"",ball)) %>%
mutate(over=gsub("\\.\\d+","",over))
#Calculate the number of maiden overs
c <- summarise(group_by(b,bowler,over),sum(runs,wides,noballs))
names(c) <- c("bowler","over","runsConceded")
d <-summarize(group_by(c,bowler),maidens=sum(runsConceded==0))
#Compute total runs conceded (runs_wides+noballs)
e <- summarize(group_by(c,bowler),runs=sum(runsConceded))
# Calculate the number of overs bowled by each bwler
f <- select(c,bowler,over)
g <- summarise(group_by(f,bowler),overs=length(unique(over)))
#Compute number of wickets
h <- b %>%
select(bowler,wicketKind,wicketPlayerOut) %>%
filter(wicketPlayerOut != "nobody")
i <- summarise(group_by(h,bowler),wickets=length(wicketPlayerOut))
#Join the over & maidens
j <- full_join(g,d,by="bowler")
# Add runs
k <- full_join(j,e,by="bowler")
# Add wickets
l <- full_join(k,i,by="bowler")
# Set NAs to 0 if there are any
if(sum(is.na(l$wickets)) != 0){
l[is.na(l$wickets),]$wickets=0
}
# Arrange in descending order of wickets and runs and ascending order for maidens
l <-arrange(l,desc(wickets),desc(runs),maidens)
l$ER = l$runs/l$overs
x_lower <- quantile(l$wickets,p=0.66,na.rm = TRUE)
y_lower <- quantile(l$ER,p=0.66,na.rm = TRUE)
plot.title <- paste("Wickets-ER of ", t1, " in all matches against ", t2)
if(plot == 1){ #ggplot2
l %>%
mutate(quadrant = case_when(wickets > x_lower & ER > y_lower ~ "Q1",
wickets <= x_lower & ER > y_lower ~ "Q2",
wickets <= x_lower & ER <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wickets,ER,color=quadrant)) +
geom_text(aes(wickets,ER,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets") + ylab("Economy rate") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- l %>%
mutate(quadrant = case_when(wickets > x_lower & ER > y_lower ~ "Q1",
wickets <= x_lower & ER > y_lower ~ "Q2",
wickets <= x_lower & ER <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wickets,ER,color=quadrant)) +
geom_text(aes(wickets,ER,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets") + ylab("Economy rate") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamWicketsERPlotOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 23 Nov 2021
# Function: teamWicketsERPowerPlayPlotAllOppnAllMatches
# This function computes the wickets vs ER of team in powewrplay against all opposition in all matches
#
###########################################################################################
#' @title
#' Team wickets vs ER in powewrplay against all opposition all matches
#'
#' @description
#' This function computes wickets vs ER in powewrplay against all oppositions in all matches
#'
#' @usage
#' teamWicketsERPowerPlayPlotAllOppnAllMatches(matches,t1, plot=1)
#'
#' @param matches
#' The matches of the team against all oppositions and all matches
#'
#' @param t1
#' Team for which bowling performance is required
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' teamWicketsERPowerPlayPlotAllOppnAllMatches(matches, t1, plot=1)
#'}
#' @seealso
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesMain}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamWicketsERPowerPlayPlotAllOppnAllMatches <- function(matches,t1,plot=1) {
team=ball=totalRuns=total=wickets=wicketsPowerPlay=wicketsMiddleOvers=wicketsDeathOvers=bowler=str_extract=NULL
ggplotly=wicketPlayerOut=str_extract=quantile=quadrant=ERPowerPlay=NULL
# Filter the performance of team1
a <-filter(matches,team!=t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,date,bowler,wicketPlayerOut)
a3 <- a2 %>% group_by(bowler,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
a4 <- a3 %>% select(date,bowler,wickets) %>% distinct(date,bowler,wickets) %>% group_by(bowler) %>% summarise(wicketsPowerPlay=sum(wickets))
a21 <- select(a1,team,bowler,date,totalRuns)
a31 <- a21 %>% group_by(bowler) %>% summarise(total=sum(totalRuns),count=n(), ERPowerPlay=total/count *6)
a41 <- a31 %>% select(bowler,ERPowerPlay)
a42=inner_join(a4,a41,by="bowler")
x_lower <- 1/2 * min(a42$wicketsPowerPlay + max(a42$wicketsPowerPlay))
y_lower <- 1/2 * min(a42$ERPowerPlay + max(a42$ERPowerPlay))
x_lower <- quantile(a42$wicketsPowerPlay,p=0.66,na.rm = TRUE)
y_lower <- quantile(a42$ERPowerPlay,p=0.66,na.rm = TRUE)
plot.title <- paste("Wickets-ER Plot of", t1, "in Power play against all opposition all matches")
if(plot == 1){ #ggplot2
a42 %>%
mutate(quadrant = case_when(wicketsPowerPlay > x_lower & ERPowerPlay > y_lower ~ "Q1",
wicketsPowerPlay <= x_lower & ERPowerPlay > y_lower ~ "Q2",
wicketsPowerPlay <= x_lower & ERPowerPlay <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wicketsPowerPlay,ERPowerPlay,color=quadrant)) +
geom_text(aes(wicketsPowerPlay,ERPowerPlay,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets - Power play") + ylab("Economy rate - Power play") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- a42 %>%
mutate(quadrant = case_when(wicketsPowerPlay > x_lower & ERPowerPlay > y_lower ~ "Q1",
wicketsPowerPlay <= x_lower & ERPowerPlay > y_lower ~ "Q2",
wicketsPowerPlay <= x_lower & ERPowerPlay <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wicketsPowerPlay,ERPowerPlay,color=quadrant)) +
geom_text(aes(wicketsPowerPlay,ERPowerPlay,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets - Power play") + ylab("Economy rate - Power play") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamWicketsERPowerPlayPlotAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 27 Nov 2021
# Function: teamWicketsERPowerPlayPlotMatch
# This function computes the wickets vs ER of team in powewrplay against opposition in match
#
###########################################################################################
#' @title
#' Team wickets vs ER in powewrplay against opposition in match
#'
#' @description
#' This function computes wickets vs ER in powewrplay against oppositions in match
#'
#' @usage
#' teamWicketsERPowerPlayPlotMatch(match,t1,t2, plot=1)
#'
#' @param match
#' The match of the team against opposition
#'
#' @param t1
#' Team for which bowling performance is required
#'
#' @param t2
#' Opposition Team
#'
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' teamWicketsERPowerPlayPlotMatch(match,t1,t2,plot=1)
#'}
#' @seealso
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesMain}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamWicketsERPowerPlayPlotMatch <- function(match,t1,t2,plot=1) {
team=ball=totalRuns=total=wickets=wicketsPowerPlay=wicketsMiddleOvers=wicketsDeathOvers=bowler=str_extract=NULL
ggplotly=wicketPlayerOut=str_extract=quantile=quadrant=ERPowerPlay=NULL
# Filter the performance of team1
a <-filter(match,team!=t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,date,bowler,wicketPlayerOut)
a3 <- a2 %>% group_by(bowler,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
a4 <- a3 %>% select(date,bowler,wickets) %>% distinct(date,bowler,wickets) %>% group_by(bowler) %>% summarise(wicketsPowerPlay=sum(wickets))
a21 <- select(a1,team,bowler,date,totalRuns)
a31 <- a21 %>% group_by(bowler) %>% summarise(total=sum(totalRuns),count=n(), ERPowerPlay=total/count *6)
a41 <- a31 %>% select(bowler,ERPowerPlay)
a42=inner_join(a4,a41,by="bowler")
x_lower <- quantile(a42$wicketsPowerPlay,p=0.66,na.rm = TRUE)
y_lower <- quantile(a42$ERPowerPlay,p=0.33,na.rm = TRUE)
plot.title <- paste("Wickets-ER in Power play of ", t1, " against ", t2 )
if(plot == 1){ #ggplot2
a42 %>%
mutate(quadrant = case_when(wicketsPowerPlay > x_lower & ERPowerPlay > y_lower ~ "Q1",
wicketsPowerPlay <= x_lower & ERPowerPlay > y_lower ~ "Q2",
wicketsPowerPlay <= x_lower & ERPowerPlay <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wicketsPowerPlay,ERPowerPlay,color=quadrant)) +
geom_text(aes(wicketsPowerPlay,ERPowerPlay,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets - Power play") + ylab("Economy rate - Power play") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- a42 %>%
mutate(quadrant = case_when(wicketsPowerPlay > x_lower & ERPowerPlay > y_lower ~ "Q1",
wicketsPowerPlay <= x_lower & ERPowerPlay > y_lower ~ "Q2",
wicketsPowerPlay <= x_lower & ERPowerPlay <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wicketsPowerPlay,ERPowerPlay,color=quadrant)) +
geom_text(aes(wicketsPowerPlay,ERPowerPlay,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets - Power play") + ylab("Economy rate - Power play") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamWicketsERPowerPlayPlotMatch.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 27 Nov 2021
# Function: teamWicketERPowerPlayPlotOppnAllMatches
# This function computes the wickets vs ER of team in powewrplay against opposition in all matches
#
###########################################################################################
#' @title
#' Team wickets vs ER in powewrplay against opposition all matches
#'
#' @description
#' This function computes wickets vs ER in powewrplay against oppositions in all matches
#'
#' @usage
#' teamWicketERPowerPlayPlotOppnAllMatches(matches,t1,t2,plot=1)
#'
#' @param matches
#' The matches of the team against all oppositions and all matches
#'
#' @param t1
#' Team for which bowling performance is required
#'
#' @param t2
#' Opposition Team
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' teamWicketERPowerPlayPlotOppnAllMatches(matches,t1,t2,plot=1)
#'}
#' @seealso
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesMain}}\cr
#' \code{\link{teamBowlersVsBatsmenAllOppnAllMatchesPlot}}\cr
#'
#' @export
#'
teamWicketERPowerPlayPlotOppnAllMatches <- function(matches,t1,t2,plot=1) {
team=ball=totalRuns=total=wickets=wicketsPowerPlay=wicketsMiddleOvers=wicketsDeathOvers=bowler=str_extract=NULL
ggplotly=wicketPlayerOut=str_extract=quantile=quadrant=ERPowerPlay=NULL
# Filter the performance of team1
a <-filter(matches,team!=t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,date,bowler,wicketPlayerOut)
a3 <- a2 %>% group_by(bowler,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
a4 <- a3 %>% select(date,bowler,wickets) %>% distinct(date,bowler,wickets) %>% group_by(bowler) %>% summarise(wicketsPowerPlay=sum(wickets))
a21 <- select(a1,team,bowler,date,totalRuns)
a31 <- a21 %>% group_by(bowler) %>% summarise(total=sum(totalRuns),count=n(), ERPowerPlay=total/count *6)
a41 <- a31 %>% select(bowler,ERPowerPlay)
a42=inner_join(a4,a41,by="bowler")
x_lower <- quantile(a42$wicketsPowerPlay,p=0.66,na.rm = TRUE)
y_lower <- quantile(a42$ERPowerPlay,p=0.33,na.rm = TRUE)
plot.title <- paste("Wickets-ER in Power play of ", t1, " against ", t2, " all matches")
if(plot == 1){ #ggplot2
a42 %>%
mutate(quadrant = case_when(wicketsPowerPlay > x_lower & ERPowerPlay > y_lower ~ "Q1",
wicketsPowerPlay <= x_lower & ERPowerPlay > y_lower ~ "Q2",
wicketsPowerPlay <= x_lower & ERPowerPlay <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wicketsPowerPlay,ERPowerPlay,color=quadrant)) +
geom_text(aes(wicketsPowerPlay,ERPowerPlay,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets - Power play") + ylab("Economy rate - Power play") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
} else if(plot == 2){ #ggplotly
g <- a42 %>%
mutate(quadrant = case_when(wicketsPowerPlay > x_lower & ERPowerPlay > y_lower ~ "Q1",
wicketsPowerPlay <= x_lower & ERPowerPlay > y_lower ~ "Q2",
wicketsPowerPlay <= x_lower & ERPowerPlay <= y_lower ~ "Q3",
TRUE ~ "Q4")) %>%
ggplot(aes(wicketsPowerPlay,ERPowerPlay,color=quadrant)) +
geom_text(aes(wicketsPowerPlay,ERPowerPlay,label=bowler,color=quadrant)) + geom_point() +
xlab("Wickets - Power play") + ylab("Economy rate - Power play") +
geom_vline(xintercept = x_lower,linetype="dashed") + # plot vertical line
geom_hline(yintercept = y_lower,linetype="dashed") + # plot horizontal line
ggtitle(plot.title)
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/teamWicketsERPowerPlayPlotOppnAllMatches.R |
#######################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 5 Nov 2021
# Function: topERBowlerAcrossOversAllOppnAllMatches.R
# This function computes the best ER by bowlers in all matches against all opposition in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the best ER by bowlers against all team in powerplay, middle and death overs
#'
#' @description
#' This function computes the best ER by bowlers against akk team in in powerplay, middle and death overs
#'
#' @usage
#' topERBowlerAcrossOversAllOppnAllMatches(matches,t1)
#'
#' @param matches
#' The dataframe of the matches
#'
#' @param t1
#' The 1st team of the match
#'
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' topERBowlerAcrossOversAllOppnAllMatches(matches,'England')
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
topERBowlerAcrossOversAllOppnAllMatches <- function(matches,t1) {
team=ball=totalRuns=total=ERPowerPlay=ERMiddleOvers=ERDeathOvers=quantile=bowler=str_extract=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team!=t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,team,bowler,date,totalRuns)
a3 <- a2 %>% group_by(bowler) %>% summarise(total=sum(totalRuns),count=n(), ERPowerPlay=total/count *6) %>% filter(count > quantile(count,prob=0.25,na.rm = TRUE))
a4 <- a3 %>% select(bowler,ERPowerPlay) %>% arrange(ERPowerPlay)
# Middle overs
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,team,bowler,date,totalRuns)
b3 <- b2 %>% group_by(bowler) %>% summarise(total=sum(totalRuns),count=n(), ERMiddleOvers=total/count *6) %>% filter(count > quantile(count,prob=0.25,na.rm = TRUE))
b4 <- b3 %>% select(bowler,ERMiddleOvers) %>% arrange(ERMiddleOvers)
#Death overs
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,team,bowler,date,totalRuns)
c3 <- c2 %>% group_by(bowler) %>% summarise(total=sum(totalRuns),count=n(), ERDeathOvers=total/count *6) %>% filter(count > quantile(count,prob=0.25,na.rm = TRUE))
c4 <- c3 %>% select(bowler,ERDeathOvers) %>% arrange(ERDeathOvers)
val=min(dim(a4)[1],dim(b4)[1],dim(c4)[1])
m=cbind(a4[1:val,],b4[1:val,],c4[1:val,])
m
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/topERBowlerAcrossOversAllOppnAllMatches.R |
#######################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 5 Nov 2021
# Function: topERBowlerAcrossOversOppnAllMatches.R
# This function computes the best ER by bowlers in matches against opposition in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the best ER by bowlers against team in powerplay, middle and death overs
#'
#' @description
#' This function computes the best ER by bowlers against team in in powerplay, middle and death overs
#'
#' @usage
#' topERBowlerAcrossOversOppnAllMatches(matches,t1)
#'
#' @param matches
#' The dataframe of the matches
#'
#' @param t1
#' The 1st team of the match
#'
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#'
#' topERBowlerAcrossOversOppnAllMatches.R(matches,'England')
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
topERBowlerAcrossOversOppnAllMatches <- function(matches,t1) {
team=ball=totalRuns=total=ERPowerPlay=ERMiddleOvers=ERDeathOvers=bowler=str_extract=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team!=t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,team,bowler,date,totalRuns)
a3 <- a2 %>% group_by(bowler) %>% summarise(total=sum(totalRuns),count=n(), ERPowerPlay=total/count *6)
a4 <- a3 %>% select(bowler,ERPowerPlay) %>% arrange(ERPowerPlay)
# Middle overs
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,team,bowler,date,totalRuns)
b3 <- b2 %>% group_by(bowler) %>% summarise(total=sum(totalRuns),count=n(), ERMiddleOvers=total/count *6)
b4 <- b3 %>% select(bowler,ERMiddleOvers) %>% arrange(ERMiddleOvers)
#Death overs
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,team,bowler,date,totalRuns)
c3 <- c2 %>% group_by(bowler) %>% summarise(total=sum(totalRuns),count=n(), ERDeathOvers=total/count *6)
c4 <- c3 %>% select(bowler,ERDeathOvers) %>% arrange(ERDeathOvers)
val=min(dim(a4)[1],dim(b4)[1],dim(c4)[1])
m=cbind(a4[1:val,],b4[1:val,],c4[1:val,])
m
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/topERBowlerAcrossOversOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 5 Nov 2021
# Function: topRunsBatsmenAcrossOversAllOppnAllMatches.R
# This function computes the top runs scorers in matches against all opposition in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the most runs scored by batsmen against all team in powerplay, middle and death overs
#'
#' @description
#' This function computes the most runs by batsman against all team in in powerplay, middle and death overs
#'
#' @usage
#' topRunsBatsmenAcrossOversAllOppnAllMatches(matches,t1,plot=1)
#'
#' @param matches
#' The dataframe of the matches
#'
#' @param t1
#' The 1st team of the match
#'
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Plot tne match worm plot
#' topRunsBatsmenAcrossOversAllOppnAllMatches(matches,'England')
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
topRunsBatsmenAcrossOversAllOppnAllMatches <- function(matches,t1,plot=1) {
team=ball=totalRuns=total=runsPowerPlay=runsMiddleOvers=runsDeathOvers=batsman=str_extract=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team==t1)
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,ball,totalRuns,batsman)
a3 <- a2 %>% group_by(batsman) %>% summarise(runsPowerPlay= sum(totalRuns)) %>% arrange(desc(runsPowerPlay))
# Middle overs I
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,ball,totalRuns,batsman)
b3 <- b2 %>% group_by(batsman) %>% summarise(runsMiddleOvers= sum(totalRuns)) %>% arrange(desc(runsMiddleOvers))
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,ball,totalRuns,batsman)
c3 <- c2 %>% group_by(batsman) %>% summarise(runsDeathOvers= sum(totalRuns)) %>% arrange(desc(runsDeathOvers))
val=min(dim(a3)[1],dim(b3)[1],dim(c3)[1])
m=cbind(a3[1:val,],b3[1:val,],c3[1:val,])
m
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/topRunsBatsmenAcrossOversAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 5 Nov 2021
# Function: topRunsBatsmenAcrossOversOppnAllMatches.R
# This function computes the top runs scorers in matches against opposition in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the most runs scored by batsmen against team in powerplay, middle and death overs
#'
#' @description
#' This function computes the most runs by batsman against team in in powerplay, middle and death overs
#'
#' @usage
#' topRunsBatsmenAcrossOversOppnAllMatches(matches,t1,plot=1)
#'
#' @param matches
#' The dataframe of the matches
#'
#' @param t1
#' The 1st team of the match
#'
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Plot tne match worm plot
#' topRunsBatsmenAcrossOversOppnAllMatches(matches,'England')
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
topRunsBatsmenAcrossOversOppnAllMatches <- function(matches,t1,plot=1) {
team=ball=totalRuns=total=runsPowerPlay=runsMiddleOvers=runsDeathOvers=matches=str_extract=NULL
ggplotly=batsman=NULL
# Filter the performance of team1
a <-filter(matches,team==t1)
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,ball,totalRuns,batsman)
a3 <- a2 %>% group_by(batsman) %>% summarise(runsPowerPlay= sum(totalRuns)) %>% arrange(desc(runsPowerPlay))
# Middle overs I
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,ball,totalRuns,batsman)
b3 <- b2 %>% group_by(batsman) %>% summarise(runsMiddleOvers= sum(totalRuns)) %>% arrange(desc(runsMiddleOvers))
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,ball,totalRuns,batsman)
c3 <- c2 %>% group_by(batsman) %>% summarise(runsDeathOvers= sum(totalRuns)) %>% arrange(desc(runsDeathOvers))
val=min(dim(a3)[1],dim(b3)[1],dim(c3)[1])
m=cbind(a3[1:val,],b3[1:val,],c3[1:val,])
m
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/topRunsBatsmenAcrossOversOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 5 Nov 2021
# Function: topSRBatsmenAcrossOversAllOppnAllMatches.R
# This function computes the highest SR by batsmen in matches against all opposition in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the highest SR by batsmen against all team in powerplay, middle and death overs
#'
#' @description
#' This function computes the highest SR by batsmen by batsman against all team in in powerplay, middle and death overs
#'
#' @usage
#' topSRBatsmenAcrossOversAllOppnAllMatches(matches,t1)
#'
#' @param matches
#' The dataframe of the matches
#'
#' @param t1
#' The team of the match
#'
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Plot tne match worm plot
#' topSRBatsmenAcrossOversAllOppnAllMatches(matches,'England')
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
topSRBatsmenAcrossOversAllOppnAllMatches <- function(matches,t1) {
team=ball=totalRuns=total=SRinPowerpPlay=SRinMiddleOvers=SRinDeathOvers=batsman=str_extract=runs=count=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team==t1)
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,ball,totalRuns,batsman,date)
a3 <- a2 %>% group_by(batsman) %>% summarise(runs=sum(totalRuns),count=n(), SRinPowerpPlay=runs/count*100) %>% arrange(desc(SRinPowerpPlay)) %>%
select(batsman,SRinPowerpPlay)
# Middle overs I
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,ball,totalRuns,batsman,date)
b3 <- b2 %>% group_by(batsman) %>% summarise(runs=sum(totalRuns),count=n(), SRinMiddleOvers=runs/count*100) %>% arrange(desc(SRinMiddleOvers)) %>%
select(batsman,SRinMiddleOvers)
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,ball,totalRuns,batsman,date)
c3 <- c2 %>% group_by(batsman) %>% summarise(runs=sum(totalRuns),count=n(), SRinDeathOvers=runs/count*100) %>% arrange(desc(SRinDeathOvers)) %>%
select(batsman,SRinDeathOvers)
val=min(dim(a3)[1],dim(b3)[1],dim(c3)[1])
m=cbind(a3[1:val,],b3[1:val,],c3[1:val,])
m
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/topSRBatsmenAcrossOversAllOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 5 Nov 2021
# Function: topSRBatsmenAcrossOversOppnAllMatches.R
# This function computes the highest SR by batsmen in matches against opposition in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the highest SR by batsmen against team in powerplay, middle and death overs
#'
#' @description
#' This function computes the highest SR by batsmen by batsman against team in in powerplay, middle and death overs
#'
#' @usage
#' topSRBatsmenAcrossOversOppnAllMatches(matches,t1,plot=1)
#'
#' @param matches
#' The dataframe of the matches
#'
#' @param t1
#' The 1st team of the match
#'
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Plot tne match worm plot
#' topSRBatsmenAcrossOversOppnAllMatches(matches,'England')
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
topSRBatsmenAcrossOversOppnAllMatches <- function(matches,t1,plot=1) {
team=ball=totalRuns=total=SRinPowerpPlay=SRinMiddleOvers=SRinDeathOvers=batsman=runs=str_extract=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team==t1)
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,ball,totalRuns,batsman,date)
a3 <- a2 %>% group_by(batsman) %>% summarise(runs=sum(totalRuns),count=n(), SRinPowerpPlay=runs/count*100) %>% arrange(desc(SRinPowerpPlay)) %>%
select(batsman,SRinPowerpPlay)
# Middle overs I
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,ball,totalRuns,batsman,date)
b3 <- b2 %>% group_by(batsman) %>% summarise(runs=sum(totalRuns),count=n(), SRinMiddleOvers=runs/count*100) %>% arrange(desc(SRinMiddleOvers)) %>%
select(batsman,SRinMiddleOvers)
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,ball,totalRuns,batsman,date)
c3 <- c2 %>% group_by(batsman) %>% summarise(runs=sum(totalRuns),count=n(), SRinDeathOvers=runs/count*100) %>% arrange(desc(SRinDeathOvers)) %>%
select(batsman,SRinDeathOvers)
val=min(dim(a3)[1],dim(b3)[1],dim(c3)[1])
m=cbind(a3[1:val,],b3[1:val,],c3[1:val,])
m
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/topSRBatsmenAcrossOversOppnAllMatches.R |
########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 5 Nov 2021
# Function: topWicketsBowlerAcrossOversAllOppnAllMatches
# This function best wicket takes in all matches against all opposition in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the most wickets by bowlers against all team in powerplay, middle and death overs
#'
#' @description
#' This function computes the highest wickets by bowlers against all team in in powerplay, middle and death overs
#'
#' @usage
#' topWicketsBowlerAcrossOversAllOppnAllMatches(matches,t1)
#'
#' @param matches
#' The dataframe of the matches
#'
#' @param t1
#' The 1st team of the match
#'
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Plot tne match worm plot
#' topWicketsBowlerAcrossOversAllOppnAllMatches(matches,'England')
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
topWicketsBowlerAcrossOversAllOppnAllMatches <- function(matches,t1) {
team=ball=totalRuns=total=wickets=wicketsPowerPlay=wicketsMiddleOvers=wicketsDeathOvers=bowler=str_extract=NULL
ggplotly=wicketPlayerOut=NULL
# Filter the performance of team1
a <-filter(matches,team!=t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,date,bowler,wicketPlayerOut)
a3 <- a2 %>% group_by(bowler,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
a4 <- a3 %>% select(date,bowler,wickets) %>% distinct(date,bowler,wickets) %>% group_by(bowler) %>% summarise(wicketsPowerPlay=sum(wickets)) %>%
arrange(desc(wicketsPowerPlay))
# Middle overs
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,date,bowler,wicketPlayerOut)
b3 <- b2 %>% group_by(bowler,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
b4 <- b3 %>% select(date,bowler,wickets) %>% distinct(date,bowler,wickets) %>% group_by(bowler) %>% summarise(wicketsMiddleOvers=sum(wickets)) %>%
arrange(desc(wicketsMiddleOvers))
#Death overs
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,date,bowler,wicketPlayerOut)
c3 <- c2 %>% group_by(bowler,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
c4 <- c3 %>% select(date,bowler,wickets) %>% distinct(date,bowler,wickets) %>% group_by(bowler) %>% summarise(wicketsDeathOvers=sum(wickets)) %>%
arrange(desc(wicketsDeathOvers))
val=min(dim(a4)[1],dim(b4)[1],dim(c4)[1])
m=cbind(a4[1:val,],b4[1:val,],c4[1:val,])
m
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/topWicketsBowlerAcrossOversAllOppnAllMatches.R |
########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 5 Nov 2021
# Function: topWicketsBowlerAcrossOversOppnAllMatches
# This function computes the best ER by bowlers in matches against opposition in powerplay, middle and death overs
#
###########################################################################################
#' @title
#' Compute the best ER by bowlers against team in powerplay, middle and death overs
#'
#' @description
#' This function computes the highest wickets by bowlers against team in in powerplay, middle and death overs
#'
#' @usage
#' topWicketsBowlerAcrossOversOppnAllMatches(matches,t1,plot=1)
#'
#' @param matches
#' The dataframe of the matches
#'
#' @param t1
#' The 1st team of the match
#'
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#'
#' # Plot tne match worm plot
#' topWicketsBowlerAcrossOversOppnAllMatches(matches,'England')
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
topWicketsBowlerAcrossOversOppnAllMatches <- function(matches,t1,plot=1) {
team=ball=totalRuns=total=wickets=wicketsPowerPlay=wicketsMiddleOvers=wicketsDeathOvers=bowler=wicketPlayerOut=str_extract=NULL
ggplotly=NULL
# Filter the performance of team1
a <-filter(matches,team!=t1)
# Power play
a1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 0.1, 5.9))
a2 <- select(a1,date,bowler,wicketPlayerOut)
a3 <- a2 %>% group_by(bowler,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
a4 <- a3 %>% select(date,bowler,wickets) %>% distinct(date,bowler,wickets) %>% group_by(bowler) %>% summarise(wicketsPowerPlay=sum(wickets)) %>%
arrange(desc(wicketsPowerPlay))
# Middle overs
b1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 6.1, 15.9))
b2 <- select(b1,date,bowler,wicketPlayerOut)
b3 <- b2 %>% group_by(bowler,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
b4 <- b3 %>% select(date,bowler,wickets) %>% distinct(date,bowler,wickets) %>% group_by(bowler) %>% summarise(wicketsMiddleOvers=sum(wickets)) %>%
arrange(desc(wicketsMiddleOvers))
#Death overs
c1 <- a %>% filter(between(as.numeric(str_extract(ball, "\\d+(\\.\\d+)?$")), 16.1, 20.0))
c2 <- select(c1,date,bowler,wicketPlayerOut)
c3 <- c2 %>% group_by(bowler,date) %>% filter(wicketPlayerOut != "nobody") %>% mutate(wickets =n())
c4 <- c3 %>% select(date,bowler,wickets) %>% distinct(date,bowler,wickets) %>% group_by(bowler) %>% summarise(wicketsDeathOvers=sum(wickets)) %>%
arrange(desc(wicketsDeathOvers))
val=min(dim(a4)[1],dim(b4)[1],dim(c4)[1])
m=cbind(a4[1:val,],b4[1:val,],c4[1:val,])
m
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/topWicketsBowlerAcrossOversOppnAllMatches.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 25 Dec 2022
# Function: winProbabilityDL
# This function computes the ball by ball win probability using Deep Learning Keras
#
###########################################################################################
#' @title
#' Plot the win probability using Deep Learning model
#'
#' @description
#' This function plots the win probability of the teams in a T20 match
#'
#' @usage
#' winProbabilityDL(match,t1,t2,plot=1)
#'
#' @param match
#' The dataframe of the match
#'
#' @param t1
#' The 1st team of the match
#'
#' @param t2
#' the 2nd team in the match
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' #Get the match details
#' a <- getMatchDetails("England","Pakistan","2006-09-05",dir="../temp")
#'
#' # Plot tne match worm plot
#' winProbabilityDL(a,'England',"Pakistan")
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
winProbabilityDL <- function(match,t1,t2,plot=1){
team=ball=totalRuns=wicketPlayerOut=ballsRemaining=runs=numWickets=runsMomentum=perfIndex=isWinner=NULL
predict=ml_model=winProbability=ggplotly=runs=runRate=batsman=bowler=NULL
batsmanIdx=bowlerIdx=NULL
if (match$winner[1] == "NA") {
print("Match no result ************************")
return()
}
team1Size=0
requiredRuns=0
# Read batsman, bowler vectors
batsmanMap=readRDS("batsmanMap.rds")
bowlerMap=readRDS("bowlerMap.rds")
teams=unique(match$team)
teamA=teams[1]
# Filter the performance of team1
a <-filter(match,team==teamA)
#Balls in team 1's innings
ballsIn1stInnings= dim(a)[1]
b <- select(a,batsman, bowler,ball,totalRuns,wicketPlayerOut,team1,team2,date)
c <-mutate(b,ball=gsub("1st\\.","",ball))
# Compute the total runs scored by team
d <- mutate(c,runs=cumsum(totalRuns))
# Check if team1 won or lost the match
if(match$winner[1]== teamA){
d$isWinner=1
} else{
d$isWinner=0
}
#Get the ball num
d$ballNum = seq.int(nrow(d))
# Compute the balls remaining for the team
d$ballsRemaining = ballsIn1stInnings - d$ballNum +1
# Wickets lost by team
d$wicketNum = d$wicketPlayerOut != "nobody"
d=d %>% mutate(numWickets=cumsum(d$wicketNum==TRUE))
#Performance index is based on run rate (runs scored/ ball number) with wickets in hand
d$perfIndex = (d$runs/d$ballNum) * (11 - d$numWickets)
# Compute run rate
d$runRate = (d$runs/d$ballNum)
d$runsMomentum = (11 - d$numWickets)/d$ballsRemaining
df8 = select(d, batsman,bowler,ballNum, ballsRemaining, runs, runRate,numWickets,runsMomentum,perfIndex, isWinner)
df9=left_join(df8,batsmanMap)
df9=left_join(df9,bowlerMap)
dfa = select(df9, batsmanIdx,bowlerIdx,ballNum,ballsRemaining,runs,runRate,numWickets,
runsMomentum,perfIndex, isWinner)
print(dim(dfa))
#############################################################################################
######## Team 2
# Compute for Team 2
# Required runs is the team made by team 1 + 1
requiredRuns=d[dim(d)[1],]$runs +1
teamB=teams[2]
# Filter the performance of team1
a1 <-filter(match,team==teamB)
#Balls in team 1's innings
ballsIn2ndInnings= dim(a1)[1] + 1
b1 <- select(a1,batsman,bowler,ball,totalRuns,wicketPlayerOut,team1,team2,date)
c1 <-mutate(b1,ball=gsub("2nd\\.","",ball))
# Compute total Runs
d1 <- mutate(c1,runs=cumsum(totalRuns))
# Check of team2 is winner
if(match$winner[1]== teamB){
d1$isWinner=1
} else{
d1$isWinner=0
}
# Compute ball number
d1$ballNum= ballsIn1stInnings + seq.int(nrow(d1))
# Compute remaining balls in 2nd innings
d1$ballsRemaining= ballsIn2ndInnings - seq.int(nrow(d1))
# Compute wickets remaining
d1$wicketNum = d1$wicketPlayerOut != "nobody"
d1=d1 %>% mutate(numWickets=cumsum(d1$wicketNum==TRUE))
ballNum=d1$ballNum - ballsIn1stInnings
#Performance index is based on run rate (runs scored/ ball number) with wickets in hand
d1$perfIndex = (d1$runs/ballNum) * (11 - d1$numWickets)
#Compute required runs
d1$requiredRuns = requiredRuns - d1$runs
d1$runRate = (d1$requiredRuns/d1$ballsRemaining)
d1$runsMomentum = (11 - d1$numWickets)/d1$ballsRemaining
# Rename required runs as runs
df10 = select(d1,batsman,bowler,ballNum,ballsRemaining, requiredRuns,runRate,numWickets,runsMomentum,perfIndex, isWinner)
names(df10) =c("batsman","bowler","ballNum","ballsRemaining","runs","runRate","numWickets","runsMomentum","perfIndex","isWinner")
print(dim(df10))
df11=left_join(df10,batsmanMap)
df11=left_join(df11,bowlerMap)
df2=rbind(df9,df11)
dfb = select(df11, batsmanIdx,bowlerIdx,ballNum,ballsRemaining,runs,runRate,numWickets,
runsMomentum,perfIndex, isWinner)
print(dim(dfb))
# load the model
m=predict(dl_model,dfa,type = "prob")
m1=m*100
m2=matrix(m1)
n=predict(dl_model,dfb,type="prob")
n1=n*100
n2=matrix(n1)
m3= 100-n2
n3=100-m2
team1=rbind(m2,m3)
team2=rbind(n3,n2)
team11=as.data.frame(cbind(df2$ballNum,team1))
names(team11) = c("ballNum","winProbability")
team22=as.data.frame(cbind(df2$ballNum,team2))
names(team22) = c("ballNum","winProbability")
# Add labels to chart team 1
#Mark when players were dismissed
k <- cbind(b,m1)
k$ballNum = seq.int(nrow(k))
k1= filter(k,wicketPlayerOut != "nobody")
k2 = select(k1,ballNum,m1,wicketPlayerOut)
#print(k2)
# Mark when batsman started
batsmen = unique(k$batsman)
p = data.frame(matrix(nrow = 0, ncol = dim(k[2])))
for(bman in batsmen){
l <-k %>% filter(batsman == bman)
n=l[1,]
p=rbind(p,n)
}
p1 = select(p,ballNum,m1,batsman)
#print(p1)
# Add labels to team 2
#Mark when players were dismissed
r <- cbind(b1,n1)
r$ballNum = seq.int(nrow(r))
r1= filter(r,wicketPlayerOut != "nobody")
r2 = select(r1,ballNum,n1,wicketPlayerOut)
# Mark when batsman started
batsmen = unique(r$batsman)
s = data.frame(matrix(nrow = 0, ncol = dim(k[2])))
for(bman1 in batsmen){
t1 <-r %>% filter(batsman == bman1)
t2=t1[1,]
s=rbind(s,t2)
}
s1 = select(s,ballNum,n1,batsman)
# Plot both lines
if(plot ==1){ #ggplot
df3 = as.data.frame(cbind(d$ballNum,m1))
names(df3) <- c("ballNum","winProbability")
df4 = as.data.frame(cbind(d1$ballNum,n1))
names(df4) <- c("ballNum","winProbability")
maxBallNum = max(df3$ballNum)
df4$ballNum = df4$ballNum - maxBallNum
g <- ggplot() +
geom_line(data = df3, aes(x = ballNum, y = winProbability, color = teamA)) +
geom_line(data = df4, aes(x = ballNum, y = winProbability, color = teamB))+
geom_point(data=k2, aes(x=ballNum, y=m1,color="blue"),shape=15) +
geom_text(data=k2, aes(x=ballNum,y=m1,label=wicketPlayerOut,color="blue"),nudge_x =0.5,nudge_y = 0.5)+
geom_point(data=p1, aes(x=ballNum, y=m1,colour="red"),shape=16) +
geom_text(data=p1, aes(x=ballNum,y=m1,label=batsman,colour="red"),nudge_x =0.5,nudge_y = 0.5) +
geom_point(data=r2, aes(x=ballNum, y=n1,colour="black"),shape=15) +
geom_text(data=r2, aes(x=ballNum,y=n1,label=wicketPlayerOut,colour="black"),nudge_x =0.5,nudge_y = 0.5) +
geom_point(data=s1, aes(x=ballNum, y=n1,colour="grey"),shape=16) +
geom_text(data=s1, aes(x=ballNum,y=n1,label=batsman,colour="grey"),nudge_x =0.5,nudge_y = 0.5)+
geom_vline(xintercept=36, linetype="dashed", color = "red") +
geom_vline(xintercept=96, linetype="dashed", color = "red") +
ggtitle("Ball-by-ball Deep Learning Win Probability (Overlapping)")
ggplotly(g)
}else { #ggplotly
g <- ggplot() +
geom_line(data = team11, aes(x = ballNum, y = winProbability, color = teamA)) +
geom_line(data = team22, aes(x = ballNum, y = winProbability, color = teamB))+
ggtitle("Ball-by-ball Deep Learning Win Probability (Side-by-side)")
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/winProbDL.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 28 Feb 2023
# Function: winProbabilityGAN
# This function computes the ball by ball win probability using GAN and synthetic data
#
###########################################################################################
#' @title
#' Plot the win probability using GAN model
#'
#' @description
#' This function plots the win probability of the teams in a T20 match
#'
#' @usage
#' winProbabilityGAN(match,t1,t2,plot=1)
#'
#' @param match
#' The dataframe of the match
#'
#' @param t1
#' The 1st team of the match
#'
#' @param t2
#' the 2nd team in the match
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' #Get the match details
#' a <- getMatchDetails("England","Pakistan","2006-09-05",dir="../temp")
#'
#' # Plot tne match worm plot
#' winProbabilityGAN(a,'England',"Pakistan")
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
winProbabilityGAN <- function(match,t1,t2,plot=1){
team=ball=totalRuns=wicketPlayerOut=ballsRemaining=runs=numWickets=runsMomentum=perfIndex=isWinner=NULL
predict=ml_model=winProbability=ggplotly=runs=runRate=batsman=bowler=NULL
batsmanIdx=bowlerIdx=NULL
if (match$winner[1] == "NA") {
print("Match no result ************************")
return()
}
team1Size=0
requiredRuns=0
# Read batsman, bowler vectors
batsmanMap=readRDS("batsmanMap.rds")
bowlerMap=readRDS("bowlerMap.rds")
teamA=match$team[grep("1st.0.1",match$ball)]
# Filter the performance of team1
a <-filter(match,team==teamA)
#Balls in team 1's innings
ballsIn1stInnings= dim(a)[1]
b <- select(a,batsman, bowler,ball,totalRuns,wicketPlayerOut,team1,team2,date)
c <-mutate(b,ball=gsub("1st\\.","",ball))
# Compute the total runs scored by team
d <- mutate(c,runs=cumsum(totalRuns))
# Check if team1 won or lost the match
if(match$winner[1]== teamA){
d$isWinner=1
} else{
d$isWinner=0
}
#Get the ball num
d$ballNum = seq.int(nrow(d))
# Compute the balls remaining for the team
d$ballsRemaining = ballsIn1stInnings - d$ballNum +1
# Wickets lost by team
d$wicketNum = d$wicketPlayerOut != "nobody"
d=d %>% mutate(numWickets=cumsum(d$wicketNum==TRUE))
#Performance index is based on run rate (runs scored/ ball number) with wickets in hand
d$perfIndex = (d$runs/d$ballNum) * (11 - d$numWickets)
# Compute run rate
d$runRate = (d$runs/d$ballNum)
d$runsMomentum = (11 - d$numWickets)/d$ballsRemaining
df8 = select(d, batsman,bowler,ballNum, ballsRemaining, runs, runRate,numWickets,runsMomentum,perfIndex, isWinner)
df9=left_join(df8,batsmanMap)
df9=left_join(df9,bowlerMap)
dfa = select(df9, batsmanIdx,bowlerIdx,ballNum,ballsRemaining,runs,runRate,numWickets,
runsMomentum,perfIndex, isWinner)
print(dim(dfa))
#############################################################################################
######## Team 2
# Compute for Team 2
# Required runs is the team made by team 1 + 1
requiredRuns=d[dim(d)[1],]$runs +1
teamB=match$team[grep("2nd.0.1",match$ball)]
# Filter the performance of team1
a1 <-filter(match,team==teamB)
#Balls in team 1's innings
ballsIn2ndInnings= dim(a1)[1] + 1
b1 <- select(a1,batsman,bowler,ball,totalRuns,wicketPlayerOut,team1,team2,date)
c1 <-mutate(b1,ball=gsub("2nd\\.","",ball))
# Compute total Runs
d1 <- mutate(c1,runs=cumsum(totalRuns))
# Check of team2 is winner
if(match$winner[1]== teamB){
d1$isWinner=1
} else{
d1$isWinner=0
}
# Compute ball number
d1$ballNum= ballsIn1stInnings + seq.int(nrow(d1))
# Compute remaining balls in 2nd innings
d1$ballsRemaining= ballsIn2ndInnings - seq.int(nrow(d1))
# Compute wickets remaining
d1$wicketNum = d1$wicketPlayerOut != "nobody"
d1=d1 %>% mutate(numWickets=cumsum(d1$wicketNum==TRUE))
ballNum=d1$ballNum - ballsIn1stInnings
#Performance index is based on run rate (runs scored/ ball number) with wickets in hand
d1$perfIndex = (d1$runs/ballNum) * (11 - d1$numWickets)
#Compute required runs
d1$requiredRuns = requiredRuns - d1$runs
d1$runRate = (d1$requiredRuns/d1$ballsRemaining)
d1$runsMomentum = (11 - d1$numWickets)/d1$ballsRemaining
# Rename required runs as runs
df10 = select(d1,batsman,bowler,ballNum,ballsRemaining, requiredRuns,runRate,numWickets,runsMomentum,perfIndex, isWinner)
names(df10) =c("batsman","bowler","ballNum","ballsRemaining","runs","runRate","numWickets","runsMomentum","perfIndex","isWinner")
print(dim(df10))
df11=left_join(df10,batsmanMap)
df11=left_join(df11,bowlerMap)
df2=rbind(df9,df11)
dfb = select(df11, batsmanIdx,bowlerIdx,ballNum,ballsRemaining,runs,runRate,numWickets,
runsMomentum,perfIndex, isWinner)
print(dim(dfb))
# load the model
m=predict(gan_model,dfa,type = "prob")
m1=m*100
m2=matrix(m1)
n=predict(dl_model,dfb,type="prob")
n1=n*100
n2=matrix(n1)
m3= 100-n2
n3=100-m2
team1=rbind(m2,m3)
team2=rbind(n3,n2)
team11=as.data.frame(cbind(df2$ballNum,team1))
names(team11) = c("ballNum","winProbability")
team22=as.data.frame(cbind(df2$ballNum,team2))
names(team22) = c("ballNum","winProbability")
# Plot both lines
if(plot ==1){ #ggplot
df3 = as.data.frame(cbind(d$ballNum,m1))
names(df3) <- c("ballNum","winProbability")
df4 = as.data.frame(cbind(d1$ballNum,n1))
names(df4) <- c("ballNum","winProbability")
maxBallNum = max(df3$ballNum)
df4$ballNum = df4$ballNum - maxBallNum
g <- ggplot() +
geom_line(data = df3, aes(x = ballNum, y = winProbability, color = teamA)) +
geom_line(data = df4, aes(x = ballNum, y = winProbability, color = teamB))+
geom_vline(xintercept=36, linetype="dashed", color = "red") +
geom_vline(xintercept=96, linetype="dashed", color = "red") +
ggtitle("Ball-by-ball Deep Learning Win Probability (Overlapping)")
ggplotly(g)
}else { #ggplotly
g <- ggplot() +
geom_line(data = team11, aes(x = ballNum, y = winProbability, color = teamA)) +
geom_line(data = team22, aes(x = ballNum, y = winProbability, color = teamB))+
ggtitle("Ball-by-ball Deep Learning Win Probability (Side-by-side)")
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/winProbGAN.R |
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 25 Dec 2022
# Function: winProbabilityLR
# This function computes the ball by ball win probability using Logistic Regression model
#
###########################################################################################
#' @title
#' Plot the win probability using Logistic Regression model
#'
#' @description
#' This function plots the win probability of the teams in a T20 match
#'
#' @usage
#' winProbabilityLR(match,t1,t2,plot=1)
#'
#' @param match
#' The dataframe of the match
#'
#' @param t1
#' The 1st team of the match
#'
#' @param t2
#' the 2nd team in the match
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' #Get the match details
#' a <- getMatchDetails("England","Pakistan","2006-09-05",dir="../temp")
#'
#' # Plot tne match worm plot
#' winProbabilityLR(a,'England',"Pakistan")
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
winProbabilityLR <- function(match,t1,t2,plot=1){
team=ball=totalRuns=wicketPlayerOut=ballsRemaining=runs=numWickets=runsMomentum=perfIndex=isWinner=NULL
predict=winProbability=ggplotly=runs=runRate=batsman=bowler=NULL
if (match$winner[1] == "NA") {
print("Match no result ************************")
return()
}
team1Size=0
requiredRuns=0
teams=unique(match$team)
teamA=teams[1]
# Filter the performance of team1
a <-filter(match,team==teamA)
#Balls in team 1's innings
ballsIn1stInnings= dim(a)[1]
b <- select(a,batsman, bowler,ball,totalRuns,wicketPlayerOut,team1,team2,date)
c <-mutate(b,ball=gsub("1st\\.","",ball))
# Compute the total runs scored by team
d <- mutate(c,runs=cumsum(totalRuns))
# Check if team1 won or lost the match
if(match$winner[1]== teamA){
d$isWinner=1
} else{
d$isWinner=0
}
#Get the ball num
d$ballNum = seq.int(nrow(d))
# Compute the balls remaining for the team
d$ballsRemaining = ballsIn1stInnings - d$ballNum +1
# Wickets lost by team
d$wicketNum = d$wicketPlayerOut != "nobody"
d=d %>% mutate(numWickets=cumsum(d$wicketNum==TRUE))
#Performance index is based on run rate (runs scored/ ball number) with wickets in hand
d$perfIndex = (d$runs/d$ballNum) * (11 - d$numWickets)
# Compute run rate
d$runRate = (d$runs/d$ballNum)
d$runsMomentum = (11 - d$numWickets)/d$ballsRemaining
df = select(d, batsman,bowler,ballNum, ballsRemaining, runs, runRate,numWickets,runsMomentum,perfIndex, isWinner)
print(dim(df))
#############################################################################################
######## Team 2
# Compute for Team 2
# Required runs is the team made by team 1 + 1
requiredRuns=d[dim(d)[1],]$runs +1
teamB=teams[2]
# Filter the performance of team1
a1 <-filter(match,team==teamB)
#Balls in team 1's innings
ballsIn2ndInnings= dim(a1)[1] + 1
b1 <- select(a1,batsman,bowler,ball,totalRuns,wicketPlayerOut,team1,team2,date)
c1 <-mutate(b1,ball=gsub("2nd\\.","",ball))
# Compute total Runs
d1 <- mutate(c1,runs=cumsum(totalRuns))
# Check of team2 is winner
if(match$winner[1]== teamB){
d1$isWinner=1
} else{
d1$isWinner=0
}
# Compute ball number
d1$ballNum= ballsIn1stInnings + seq.int(nrow(d1))
# Compute remaining balls in 2nd innings
d1$ballsRemaining= ballsIn2ndInnings - seq.int(nrow(d1))
# Compute wickets remaining
d1$wicketNum = d1$wicketPlayerOut != "nobody"
d1=d1 %>% mutate(numWickets=cumsum(d1$wicketNum==TRUE))
ballNum=d1$ballNum - ballsIn1stInnings
#Performance index is based on run rate (runs scored/ ball number) with wickets in hand
d1$perfIndex = (d1$runs/ballNum) * (11 - d1$numWickets)
#Compute required runs
d1$requiredRuns = requiredRuns - d1$runs
d1$runRate = (d1$requiredRuns/d1$ballsRemaining)
d1$runsMomentum = (11 - d1$numWickets)/d1$ballsRemaining
# Rename required runs as runs
df1 = select(d1,batsman,bowler,ballNum,ballsRemaining, requiredRuns,runRate,numWickets,runsMomentum,perfIndex, isWinner)
names(df1) =c("batsman","bowler","ballNum","ballsRemaining","runs","runRate","numWickets","runsMomentum","perfIndex","isWinner")
print(dim(df1))
df2=rbind(df,df1)
# load the model
#ml_model <- readRDS("glmLR.rds")
a1=select(df,batsman,bowler,ballNum,ballsRemaining, runs,runRate,numWickets,runsMomentum,perfIndex)
m=predict(final_lr_model,a1,type = "prob")
m1=m$.pred_1*100
m2=matrix(m1)
b2=select(df1,batsman,bowler,ballNum,ballsRemaining, runs,runRate,numWickets,runsMomentum,perfIndex)
n=predict(final_lr_model,b2,type="prob")
n1=n1=n$.pred_1*100
n2=matrix(n1)
m3= 100-n2
n3=100-m2
team1=rbind(m2,m3)
team2=rbind(n3,n2)
team11=as.data.frame(cbind(df2$ballNum,team1))
names(team11) = c("ballNum","winProbability")
team22=as.data.frame(cbind(df2$ballNum,team2))
names(team22) = c("ballNum","winProbability")
# Add labels to chart team 1
#Mark when players were dismissed
k <- cbind(b,m1)
k$ballNum = seq.int(nrow(k))
k1= filter(k,wicketPlayerOut != "nobody")
k2 = select(k1,ballNum,m1,wicketPlayerOut)
#print(k2)
# Mark when batsman started
batsmen = unique(k$batsman)
p = data.frame(matrix(nrow = 0, ncol = dim(k[2])))
for(bman in batsmen){
l <-k %>% filter(batsman == bman)
n=l[1,]
p=rbind(p,n)
}
p1 = select(p,ballNum,m1,batsman)
#print(p1)
# Add labels to team 2
#Mark when players were dismissed
r <- cbind(b1,n1)
r$ballNum = seq.int(nrow(r))
r1= filter(r,wicketPlayerOut != "nobody")
r2 = select(r1,ballNum,n1,wicketPlayerOut)
#print(r2)
# Mark when batsman started
batsmen = unique(r$batsman)
s = data.frame(matrix(nrow = 0, ncol = dim(k[2])))
for(bman1 in batsmen){
t1 <-r %>% filter(batsman == bman1)
t2=t1[1,]
s=rbind(s,t2)
}
s1 = select(s,ballNum,n1,batsman)
#print(s1)
# Plot both lines
if(plot ==1){ #ggplot2
df3 = as.data.frame(cbind(d$ballNum,m1))
names(df3) <- c("ballNum","winProbability")
df4 = as.data.frame(cbind(d1$ballNum,n1))
names(df4) <- c("ballNum","winProbability")
maxBallNum = max(df3$ballNum)
df4$ballNum = df4$ballNum - maxBallNum
g <- ggplot() +
geom_line(data = df3, aes(x = ballNum, y = winProbability, color = teamA)) +
geom_line(data = df4, aes(x = ballNum, y = winProbability, color = teamB))+
geom_point(data=k2, aes(x=ballNum, y=m1,color="blue"),shape=15) +
geom_text(data=k2, aes(x=ballNum,y=m1,label=wicketPlayerOut,color="blue"),nudge_x =0.5,nudge_y = 0.5)+
geom_point(data=p1, aes(x=ballNum, y=m1,colour="red"),shape=16) +
geom_text(data=p1, aes(x=ballNum,y=m1,label=batsman,colour="red"),nudge_x =0.5,nudge_y = 0.5) +
geom_point(data=r2, aes(x=ballNum, y=n1,colour="black"),shape=15) +
geom_text(data=r2, aes(x=ballNum,y=n1,label=wicketPlayerOut,colour="black"),nudge_x =0.5,nudge_y = 0.5) +
geom_point(data=s1, aes(x=ballNum, y=n1,colour="grey"),shape=16) +
geom_text(data=s1, aes(x=ballNum,y=n1,label=batsman,colour="grey"),nudge_x =0.5,nudge_y = 0.5)+
geom_vline(xintercept=36, linetype="dashed", color = "red") +
geom_vline(xintercept=96, linetype="dashed", color = "red") +
ggtitle("Ball-by-ball Logistic Regression Win Probability (Overlapping)")
ggplotly(g)
}else { #ggplotly
g <- ggplot() +
geom_line(data = team11, aes(x = ballNum, y = winProbability, color = teamA)) +
geom_line(data = team22, aes(x = ballNum, y = winProbability, color = teamB))+
ggtitle("Ball-by-ball Logistic Regression Win Probability (Side-by-side)")
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/winProbLR.R |
##########################################################################################
##########################################################################################
# Designed and developed by Tinniam V Ganesh
# Date : 25 Dec 2022
# Function: winProbabiltyRF
# This function computes the ball by ball win probability using Random Forest model
#
###########################################################################################
#' @title
#' Plot the win probability using Random Forest model
#'
#' @description
#' This function plots the win probability of the teams in a T20 match
#'
#' @usage
#' winProbabilityRF(match,t1,t2,plot=1)
#'
#' @param match
#' The dataframe of the match
#'
#' @param t1
#' The 1st team of the match
#'
#' @param t2
#' the 2nd team in the match
#'
#' @param plot
#' Plot=1 (static), Plot=2(interactive)
#'
#' @return none
#'
#' @references
#' \url{https://cricsheet.org/}\cr
#' \url{https://gigadom.in/}\cr
#' \url{https://github.com/tvganesh/yorkrData/}
#'
#' @author
#' Tinniam V Ganesh
#' @note
#' Maintainer: Tinniam V Ganesh \email{[email protected]}
#'
#' @examples
#' \dontrun{
#' #Get the match details
#' a <- getMatchDetails("England","Pakistan","2006-09-05",dir="../temp")
#'
#' # Plot tne match worm plot
#' winProbabilityRF(a,'England',"Pakistan")
#' }
#' @seealso
#' \code{\link{getBatsmanDetails}}\cr
#' \code{\link{getBowlerWicketDetails}}\cr
#' \code{\link{batsmanDismissals}}\cr
#' \code{\link{getTeamBattingDetails}}\cr
#'
#' @export
#'
winProbabilityRF <- function(match,t1,t2,plot=1){
team=ball=totalRuns=wicketPlayerOut=ballsRemaining=runs=numWickets=runsMomentum=perfIndex=isWinner=NULL
predict=winProbability=ggplotly=runs=runRate=batsman=bowler=NULL
if (match$winner[1] == "NA") {
print("Match no result ************************")
return()
}
team1Size=0
requiredRuns=0
teamA=match$team[grep("1st.0.1",match$ball)]
# Filter the performance of team1
a <-filter(match,team==teamA)
#Balls in team 1's innings
ballsIn1stInnings= dim(a)[1]
b <- select(a,batsman, bowler, ball,totalRuns,wicketPlayerOut,team1,team2,date)
c <-mutate(b,ball=gsub("1st\\.","",ball))
# Compute the total runs scored by team
d <- mutate(c,runs=cumsum(totalRuns))
# Check if team1 won or lost the match
if(match$winner[1]== teamA){
d$isWinner=1
} else{
d$isWinner=0
}
#Get the ball num
d$ballNum = seq.int(nrow(d))
# Compute the balls remaining for the team
d$ballsRemaining = ballsIn1stInnings - d$ballNum +1
# Wickets lost by team
d$wicketNum = d$wicketPlayerOut != "nobody"
d=d %>% mutate(numWickets=cumsum(d$wicketNum==TRUE))
#Performance index is based on run rate (runs scored/ ball number) with wickets in hand
d$perfIndex = (d$runs/d$ballNum) * (11 - d$numWickets)
# Compute run rate
d$runRate = (d$runs/d$ballNum)
d$runsMomentum = (11 - d$numWickets)/d$ballsRemaining
df = select(d, batsman, bowler, ballNum, ballsRemaining, runs, runRate,numWickets,runsMomentum,perfIndex, isWinner)
print(dim(df))
#############################################################################################
######## Team 2
# Compute for Team 2
# Required runs is the team made by team 1 + 1
requiredRuns=d[dim(d)[1],]$runs +1
teamB=match$team[grep("2nd.0.1",match$ball)]
# Filter the performance of team1
a1 <-filter(match,team==teamB)
#Balls in team 1's innings
ballsIn2ndInnings= dim(a1)[1] + 1
b1 <- select(a1,batsman, bowler, ball,totalRuns,wicketPlayerOut,team1,team2,date)
c1 <-mutate(b1,ball=gsub("2nd\\.","",ball))
# Compute total Runs
d1 <- mutate(c1,runs=cumsum(totalRuns))
# Check of team2 is winner
if(match$winner[1]== teamB){
d1$isWinner=1
} else{
d1$isWinner=0
}
# Compute ball number
d1$ballNum= ballsIn1stInnings + seq.int(nrow(d1))
# Compute remaining balls in 2nd innings
d1$ballsRemaining= ballsIn2ndInnings - seq.int(nrow(d1))
# Compute wickets remaining
d1$wicketNum = d1$wicketPlayerOut != "nobody"
d1=d1 %>% mutate(numWickets=cumsum(d1$wicketNum==TRUE))
ballNum=d1$ballNum - ballsIn1stInnings
#Performance index is based on run rate (runs scored/ ball number) with wickets in hand
d1$perfIndex = (d1$runs/ballNum) * (11 - d1$numWickets)
#Compute required runs
d1$requiredRuns = requiredRuns - d1$runs
d1$runRate = (d1$requiredRuns/d1$ballsRemaining)
d1$runsMomentum = (11 - d1$numWickets)/d1$ballsRemaining
# Rename required runs as runs
df1 = select(d1,batsman, bowler, ballNum,ballsRemaining, requiredRuns,runRate,numWickets,runsMomentum,perfIndex, isWinner)
names(df1) =c("batsman","bowler","ballNum","ballsRemaining","runs","runRate","numWickets","runsMomentum","perfIndex","isWinner")
print(dim(df1))
df2=rbind(df,df1)
a1=select(df,batsman,bowler,ballNum,ballsRemaining, runs,runRate,numWickets,runsMomentum,perfIndex)
m=predict(final_model,a1,type = "prob")
m1=m$.pred_1*100
m2=matrix(m1)
b1=select(df1,batsman,bowler,ballNum,ballsRemaining, runs,runRate,numWickets,runsMomentum,perfIndex)
n=predict(final_model,b1,type="prob")
n1=n$.pred_1*100
n2=matrix(n1)
m3= 100-n2
n3=100-m2
team1=rbind(m2,m3)
team2=rbind(n3,n2)
team11=as.data.frame(cbind(df2$ballNum,team1))
names(team11) = c("ballNum","winProbability")
team22=as.data.frame(cbind(df2$ballNum,team2))
names(team22) = c("ballNum","winProbability")
# Plot both lines
if(plot ==1){ #ggplot2
ggplot() +
geom_line(data = team11, aes(x = ballNum, y = winProbability, color = teamA)) +
geom_line(data = team22, aes(x = ballNum, y = winProbability, color = teamB))+
ggtitle(bquote(atop(.("Win Probability based on Random Forest model"),
atop(italic("Data source:http://cricsheet.org/"),""))))
}else { #ggplotly
g <- ggplot() +
geom_line(data = team11, aes(x = ballNum, y = winProbability, color = teamA)) +
geom_line(data = team22, aes(x = ballNum, y = winProbability, color = teamB))+
ggtitle("Win Probability based on Random Forest model")
ggplotly(g)
}
}
| /scratch/gouwar.j/cran-all/cranData/yorkr/R/winProbRF.R |
#' Data from the young elite swimmers study
#'
#' This is the data used for the young elite swimmers
#' study (Castillo-Aguilar et al. 2021). It contains records from
#' 26 competitive swimmers from ages 10 to 16 on 5 different
#' competitive time periods.
#'
#' @format This is a data.table object containing 27 variables and 130 rows
#'
#' - \code{period}: Factor. Time periods from two competitions.
#' - \code{subject}: Factor. Subject ID.
#' - \code{sex}: Factor. Subject's sex (Male of Female).
#' - \code{age}: Numeric. Subject's age in years.
#' - \code{weight}: Numeric. Weight in kilograms.
#' - \code{height}: Numeric. Heigh in centimeters.
#' - \code{fat}: Numeric. Body fat in percentage.
#' - \code{bmi}: Numeric. Body mass index.
#' - \code{ffmi}: Numeric. Fat free mass index.
#' - \code{sp}: Numeric. Systolic blood pressure in mmHg.
#' - \code{dp}: Numeric. Diastolic blood pressure in mmHg.
#' - \code{map}: Numeric. Mean arterial pressure in mmHg.
#' - \code{pp}: Numeric. Pulse pressure in mmHg.
#' - \code{sdnn_pre}: Numeric. SDNN (Time domain parameter) pre-wingate test.
#' - \code{rmssd_pre}: Numeric. RMSSD (Time domain parameter) pre-wingate test.
#' - \code{vlf_pre}: Numeric. VLF (Frequency domain parameter) pre-wingate test.
#' - \code{lf_pre}: Numeric. LF (Frequency domain parameter) pre-wingate test.
#' - \code{hf_pre}: Numeric. HF (Frequency domain parameter) pre-wingate test.
#' - \code{sdnn_post}: Numeric. SDNN (Time domain parameter) post-wingate test.
#' - \code{rmssd_post}: Numeric. RMSSD (Time domain parameter) post-wingate test.
#' - \code{vlf_post}: Numeric. VLF (Frequency domain parameter) post-wingate test.
#' - \code{lf_post}: Numeric. LF (Frequency domain parameter) post-wingate test.
#' - \code{hf_post}: Numeric. HF (Frequency domain parameter) post-wingate test.
#' - \code{power_peak}: Numeric. Peak power output in Watts.
#' - \code{power_mean}: Numeric. Mean power output in Watts.
#' - \code{power_min}: Numeric. Minimum power output in Watts.
#' - \code{fatigue}: Numeric. Fatigue index in percentage.
#'
#' @source
#' \doi{10.3389/fphys.2021.769085}
"swimmers"
| /scratch/gouwar.j/cran-all/cranData/youngSwimmers/R/dataset.R |
#' youngSwimmers
#'
#' Data from the young elite swimmers study.
#'
#' @keywords internal
"_PACKAGE"
## usethis namespace: start
#' @importFrom data.table :=
#' @importFrom data.table .BY
#' @importFrom data.table .EACHI
#' @importFrom data.table .GRP
#' @importFrom data.table .I
#' @importFrom data.table .N
#' @importFrom data.table .NGRP
#' @importFrom data.table .SD
#' @importFrom data.table data.table
#' @importFrom lifecycle deprecated
## usethis namespace: end
NULL
| /scratch/gouwar.j/cran-all/cranData/youngSwimmers/R/youngSwimmers-package.R |
#' @export
as.data.frame.ypr_population <- function(x, ...) {
chk_unused(...)
x <- unclass(x)
as.data.frame(x)
}
#' @export
as.data.frame.ypr_populations <- function(x, ...) {
chk_unused(...)
x <- lapply(x, as.data.frame)
do.call("rbind", x)
}
#' @export
as.data.frame.ypr_ecotypes <- function(x, ...) {
chk_unused(...)
rname <- attr(x, "names")
x <- lapply(x, as.data.frame)
do.call("rbind", x)
}
| /scratch/gouwar.j/cran-all/cranData/ypr/R/as-data-frame.R |
#' @export
tibble::as_tibble
#' @export
as_tibble.ypr_population <- function(x, ...) {
chk_unused(...)
as_tibble(as.data.frame(x))
}
#' @export
as_tibble.ypr_populations <- function(x, ...) {
chk_unused(...)
as_tibble(as.data.frame(x))
}
#' @export
as_tibble.ypr_ecotypes <- function(x, ...) {
chk_unused(...)
as_tibble(as.data.frame(x))
}
| /scratch/gouwar.j/cran-all/cranData/ypr/R/as-tibble.R |
#' Coerce to an Ecotypes Object
#'
#' @param x The object to coerce.
#' @param ... Additional arguments.
#' @return An object of class ypr_ecotypes.
#' @family ecotypes
#' @export
as_ypr_ecotypes <- function(x, ...) {
UseMethod("as_ypr_ecotypes")
}
#' @describeIn as_ypr_ecotypes Coerce a data.frame to an Ecotypes Object
#'
#' @export
#' @examples
#' as_ypr_ecotypes(as.data.frame(ypr_ecotypes(Ls = c(10, 15, 20))))
as_ypr_ecotypes.data.frame <- function(x, ...) {
chk_data(x)
chk_unused(...)
x <- split(x, seq_len(nrow(x)))
x <- lapply(x, as_ypr_population)
class(x) <- "ypr_ecotypes"
check_ecotypes(x)
names(x) <- ypr_names(x)
x
}
#' @describeIn as_ypr_ecotypes Coerce a Population Object to an Ecotypes Object
#' @export
#' @examples
#' as_ypr_ecotypes(ypr_population())
as_ypr_ecotypes.ypr_population <- function(x, ...) {
check_population(x)
chk_unused(...)
x <- list(x)
class(x) <- "ypr_ecotypes"
names(x) <- ypr_names(x)
x
}
#' @describeIn as_ypr_ecotypes Coerce a Populations Object to an Ecotypes Object
#'
#' @export
#' @examples
#' as_ypr_ecotypes(ypr_populations(Ls = c(10, 15, 20)))
as_ypr_ecotypes.ypr_populations <- function(x, ...) {
check_populations(x)
chk_unused(...)
class(x) <- c("ypr_ecotypes")
check_ecotypes(x)
x
}
#' @describeIn as_ypr_ecotypes Coerce an Ecotypes Object to an Ecotypes Object
#'
#' @export
#' @examples
#' as_ypr_ecotypes(ypr_ecotypes(Ls = c(10, 15, 20)))
as_ypr_ecotypes.ypr_ecotypes <- function(x, ...) {
check_ecotypes(x)
chk_unused(...)
x
}
| /scratch/gouwar.j/cran-all/cranData/ypr/R/as-ypr-ecotypes.R |
#' Coerce to a Population Object
#'
#' @param x The object to coerce.
#' @param ... Unused.
#' @return An object of class ypr_population.
#' @family population
#' @export
as_ypr_population <- function(x, ...) {
UseMethod("as_ypr_population")
}
#' @describeIn as_ypr_population Coerce a data.frame to an Population Object
#'
#' @export
#' @examples
#' as_ypr_population(as.data.frame(ypr_population()))
as_ypr_population.data.frame <- function(x, ...) {
chk_data(x)
chk_unused(...)
do.call("ypr_population", x)
}
#' @describeIn as_ypr_population Coerce a Population Object to an Population Object
#'
#' @export
#' @examples
#' as_ypr_population(ypr_populations())
as_ypr_population.ypr_population <- function(x, ...) {
check_population(x)
chk_unused(...)
x
}
#' @describeIn as_ypr_population Coerce a Populations Object of length 1 to a Population Object
#'
#' @export
#' @examples
#' as_ypr_population(ypr_populations())
as_ypr_population.ypr_populations <- function(x, ...) {
chk_list(x)
chk_unused(...)
check_dim(x, dim = length, values = 1L)
x <- check_population(x[[1]])
x
}
#' @describeIn as_ypr_population Coerce a Ecotypes Object of length 1 to a Population Object
#'
#' @export
#' @examples
#' as_ypr_population(ypr_ecotypes())
as_ypr_population.ypr_ecotypes <- function(x, ...) {
chk_list(x)
chk_unused(...)
check_dim(x, dim = length, values = 1L)
x <- check_population(x[[1]])
x
}
| /scratch/gouwar.j/cran-all/cranData/ypr/R/as-ypr-population.R |
#' Coerce to a Populations Object
#'
#' @param x The object to coerce.
#' @param ... Unused.
#' @return An object of class ypr_ecotypes.
#' @family populations
#' @export
as_ypr_populations <- function(x, ...) {
UseMethod("as_ypr_populations")
}
#' @describeIn as_ypr_population Coerce a data.frame to a Populations Object
#'
#' @export
#' @examples
#' as_ypr_populations(as.data.frame(ypr_populations(Rk = c(3, 4))))
as_ypr_populations.data.frame <- function(x, ...) {
chk_data(x)
chk_unused(...)
x <- split(x, seq_len(nrow(x)))
x <- lapply(x, as_ypr_population)
class(x) <- "ypr_populations"
names(x) <- ypr_names(x)
x
}
#' @describeIn as_ypr_populations Coerce a Population Object to an Population Object
#'
#' @export
#' @examples
#' as_ypr_populations(ypr_population())
as_ypr_populations.ypr_population <- function(x, ...) {
check_population(x)
chk_unused(...)
x <- list(x)
class(x) <- "ypr_populations"
names(x) <- ypr_names(x)
x
}
#' @describeIn as_ypr_populations Coerce a Populations Object of length 1 to a Population Object
#'
#' @export
#' @examples
#' as_ypr_populations(ypr_populations())
as_ypr_populations.ypr_populations <- function(x, ...) {
check_populations(x)
chk_unused(...)
x
}
#' @describeIn as_ypr_populations Coerce a Ecotypes Object of length 1 to a Population Object
#'
#' @export
#' @examples
#' as_ypr_populations(ypr_ecotypes())
as_ypr_populations.ypr_ecotypes <- function(x, ...) {
check_ecotypes(x)
chk_unused(...)
class(x) <- "ypr_populations"
x
}
| /scratch/gouwar.j/cran-all/cranData/ypr/R/as-ypr-populations.R |
check_parameters <- function(tmax, k, Linf, t0, k2, Linf2, L2, Wb, Ls, Sp, es, tR, Rk, BH, fb, n, nL, Ln, Sm, pi, Lv, Vp, Llo, Lup, rho, Hm, Nc, Wa, fa, Rmax, q, RPR) {
chk_s3_class(tmax, "integer")
chk_scalar(tmax)
chk_not_any_na(tmax)
chk_range(tmax, c(1L, 100L))
chk_s3_class(k, "numeric")
chk_scalar(k)
chk_not_any_na(k)
chk_range(k, c(0.015, 15))
chk_s3_class(Linf, "numeric")
chk_scalar(Linf)
chk_not_any_na(Linf)
chk_range(Linf, c(1, 1000))
chk_s3_class(t0, "numeric")
chk_scalar(t0)
chk_not_any_na(t0)
chk_range(t0, c(-10, 10))
chk_s3_class(k2, "numeric")
chk_scalar(k2)
chk_not_any_na(k2)
chk_range(k2, c(0, 15))
chk_s3_class(Linf2, "numeric")
chk_scalar(Linf2)
chk_not_any_na(Linf2)
chk_range(Linf2, c(1, 1000))
chk_s3_class(L2, "numeric")
chk_scalar(L2)
chk_not_any_na(L2)
chk_range(L2, c(-100, 1000))
chk_s3_class(Wb, "numeric")
chk_scalar(Wb)
chk_not_any_na(Wb)
chk_range(Wb, c(2, 4))
chk_s3_class(Ls, "numeric")
chk_scalar(Ls)
chk_not_any_na(Ls)
chk_range(Ls, c(-100, 1000))
chk_s3_class(Sp, "numeric")
chk_scalar(Sp)
chk_not_any_na(Sp)
chk_range(Sp, c(0, 1000))
chk_s3_class(es, "numeric")
chk_scalar(es)
chk_not_any_na(es)
chk_range(es, c(0.01, 1))
chk_s3_class(tR, "integer")
chk_scalar(tR)
chk_not_any_na(tR)
chk_range(tR, c(0L, 10L))
chk_s3_class(Rk, "numeric")
chk_scalar(Rk)
chk_not_any_na(Rk)
chk_range(Rk, c(1, 100))
chk_s3_class(BH, "integer")
chk_scalar(BH)
chk_not_any_na(BH)
chk_range(BH, c(0L, 1L))
chk_s3_class(fb, "numeric")
chk_scalar(fb)
chk_not_any_na(fb)
chk_range(fb, c(0.5, 2))
chk_s3_class(n, "numeric")
chk_scalar(n)
chk_not_any_na(n)
chk_range(n, c(0, 1))
chk_s3_class(nL, "numeric")
chk_scalar(nL)
chk_not_any_na(nL)
chk_range(nL, c(0, 1))
chk_s3_class(Ln, "numeric")
chk_scalar(Ln)
chk_not_any_na(Ln)
chk_range(Ln, c(-100, 1000))
chk_s3_class(Sm, "numeric")
chk_scalar(Sm)
chk_not_any_na(Sm)
chk_range(Sm, c(0, 1))
chk_s3_class(pi, "numeric")
chk_scalar(pi)
chk_not_any_na(pi)
chk_range(pi, c(0, 1))
chk_s3_class(Lv, "numeric")
chk_scalar(Lv)
chk_not_any_na(Lv)
chk_range(Lv, c(-100, 1000))
chk_s3_class(Vp, "numeric")
chk_scalar(Vp)
chk_not_any_na(Vp)
chk_range(Vp, c(0, 100))
chk_s3_class(Llo, "numeric")
chk_scalar(Llo)
chk_not_any_na(Llo)
chk_range(Llo, c(0, 1000))
chk_s3_class(Lup, "numeric")
chk_scalar(Lup)
chk_not_any_na(Lup)
chk_range(Lup, c(0, 1000))
chk_s3_class(rho, "numeric")
chk_scalar(rho)
chk_not_any_na(rho)
chk_range(rho, c(0, 1))
chk_s3_class(Hm, "numeric")
chk_scalar(Hm)
chk_not_any_na(Hm)
chk_range(Hm, c(0, 1))
chk_s3_class(Nc, "numeric")
chk_scalar(Nc)
chk_not_any_na(Nc)
chk_range(Nc, c(0, 1))
chk_s3_class(Wa, "numeric")
chk_scalar(Wa)
chk_not_any_na(Wa)
chk_range(Wa, c(0.001, 0.1))
chk_s3_class(fa, "numeric")
chk_scalar(fa)
chk_not_any_na(fa)
chk_range(fa, c(1e-04, 100))
chk_s3_class(Rmax, "numeric")
chk_scalar(Rmax)
chk_not_any_na(Rmax)
chk_range(Rmax, c(1, 1e+06))
chk_s3_class(q, "numeric")
chk_scalar(q)
chk_not_any_na(q)
chk_range(q, c(0, 1))
chk_s3_class(RPR, "numeric")
chk_scalar(RPR)
chk_not_any_na(RPR)
chk_range(RPR, c(0, 100))
invisible(list(tmax = tmax, k = k, Linf = Linf, t0 = t0, k2 = k2, Linf2 = Linf2,
L2 = L2, Wb = Wb, Ls = Ls, Sp = Sp, es = es, tR = tR, Rk = Rk,
BH = BH, fb = fb, n = n, nL = nL, Ln = Ln, Sm = Sm, pi = pi,
Lv = Lv, Vp = Vp, Llo = Llo, Lup = Lup, rho = rho, Hm = Hm,
Nc = Nc, Wa = Wa, fa = fa, Rmax = Rmax, q = q, RPR = RPR))
}
| /scratch/gouwar.j/cran-all/cranData/ypr/R/check-parameters.R |
#' Check Population
#'
#' Checks if an ypr_population object with valid parameter values.
#'
#' @inherit chk::check_data
#' @family check
#' @export
#'
#' @examples
#' check_population(ypr_population())
check_population <- function(x, x_name = NULL) {
if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x))
chk_string(x_name, x_name = "x_name")
chk_s3_class(x, "ypr_population", x_name = x_name)
chk_named(x, x_name = x_name)
chk_unique(names(x), x_name = x_name)
chk_superset(names(x), parameters(), x_name = x_name)
do.call("check_parameters", x)
invisible(x)
}
#' Check Populations
#'
#' Checks if an ypr_populations object with valid parameter values.
#'
#' @inherit chk::check_data
#' @family check
#' @export
#'
#' @examples
#' check_populations(ypr_populations())
check_populations <- function(x, x_name = NULL) {
if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x))
chk_list(x, x_name = x_name)
chk_s3_class(x, "ypr_populations", x_name)
x_name <- paste("elements of", x_name)
chk_all(x, check_population, x_name = x_name)
invisible(x)
}
#' Check Ecotypes
#'
#' Checks if an ypr_ecotypes object with valid parameter values.
#'
#' @inherit chk::check_data
#' @family check
#' @export
#'
#' @examples
#' check_ecotypes(ypr_ecotypes())
check_ecotypes <- function(x, x_name = NULL) {
if (is.null(x_name)) x_name <- deparse_backtick_chk(substitute(x))
chk_list(x, x_name = x_name)
chk_s3_class(x, "ypr_ecotypes", x_name)
x_name <- paste("elements of", x_name)
chk_all(x, check_population, x_name = x_name)
check_same(x, "BH")
check_same(x, "Rk")
check_same(x, "tR")
check_same(x, "Rmax")
check_same(x, "pi")
check_same(x, "Nc")
check_same(x, "Hm")
check_same(x, "Llo")
check_same(x, "Lup")
check_same(x, "rho")
check_same(x, "q")
data <- as_tibble(x)
data$RPR <- NULL
if(anyDuplicated(data)) {
chk::abort_chk("ecotypes must have unique life-histories.", tidy = FALSE)
}
invisible(x)
}
check_same <- function(x, parameter) {
class(x) <- "ypr_populations"
values <- ypr_get_par(x, parameter)
if (length(unique(values)) != 1) {
chk::abort_chk("`", parameter, "` must be the same across all elements.", tidy = FALSE)
}
}
| /scratch/gouwar.j/cran-all/cranData/ypr/R/check.R |
check_parameters <- function(tmax, k, Linf, t0, k2, Linf2, L2, Wb, Ls, Sp, es, tR, Rk, BH, fb, n, nL, Ln, Sm, pi, Lv, Vp, Llo, Lup, rho, Hm, Nc, Wa, fa, Rmax, q, RPR) {
chk_s3_class(tmax, "integer")
chk_scalar(tmax)
chk_not_any_na(tmax)
chk_range(tmax, c(1L, 100L))
chk_s3_class(k, "numeric")
chk_scalar(k)
chk_not_any_na(k)
chk_range(k, c(0.015, 15))
chk_s3_class(Linf, "numeric")
chk_scalar(Linf)
chk_not_any_na(Linf)
chk_range(Linf, c(1, 1000))
chk_s3_class(t0, "numeric")
chk_scalar(t0)
chk_not_any_na(t0)
chk_range(t0, c(-10, 10))
chk_s3_class(k2, "numeric")
chk_scalar(k2)
chk_not_any_na(k2)
chk_range(k2, c(0, 15))
chk_s3_class(Linf2, "numeric")
chk_scalar(Linf2)
chk_not_any_na(Linf2)
chk_range(Linf2, c(1, 1000))
chk_s3_class(L2, "numeric")
chk_scalar(L2)
chk_not_any_na(L2)
chk_range(L2, c(-100, 1000))
chk_s3_class(Wb, "numeric")
chk_scalar(Wb)
chk_not_any_na(Wb)
chk_range(Wb, c(2, 4))
chk_s3_class(Ls, "numeric")
chk_scalar(Ls)
chk_not_any_na(Ls)
chk_range(Ls, c(-100, 1000))
chk_s3_class(Sp, "numeric")
chk_scalar(Sp)
chk_not_any_na(Sp)
chk_range(Sp, c(0, 1000))
chk_s3_class(es, "numeric")
chk_scalar(es)
chk_not_any_na(es)
chk_range(es, c(0.01, 1))
chk_s3_class(tR, "integer")
chk_scalar(tR)
chk_not_any_na(tR)
chk_range(tR, c(0L, 10L))
chk_s3_class(Rk, "numeric")
chk_scalar(Rk)
chk_not_any_na(Rk)
chk_range(Rk, c(0, 100))
chk_s3_class(BH, "integer")
chk_scalar(BH)
chk_not_any_na(BH)
chk_range(BH, c(0L, 1L))
chk_s3_class(fb, "numeric")
chk_scalar(fb)
chk_not_any_na(fb)
chk_range(fb, c(0.5, 2))
chk_s3_class(n, "numeric")
chk_scalar(n)
chk_not_any_na(n)
chk_range(n, c(0, 1))
chk_s3_class(nL, "numeric")
chk_scalar(nL)
chk_not_any_na(nL)
chk_range(nL, c(0, 1))
chk_s3_class(Ln, "numeric")
chk_scalar(Ln)
chk_not_any_na(Ln)
chk_range(Ln, c(-100, 1000))
chk_s3_class(Sm, "numeric")
chk_scalar(Sm)
chk_not_any_na(Sm)
chk_range(Sm, c(0, 1))
chk_s3_class(pi, "numeric")
chk_scalar(pi)
chk_not_any_na(pi)
chk_range(pi, c(0, 1))
chk_s3_class(Lv, "numeric")
chk_scalar(Lv)
chk_not_any_na(Lv)
chk_range(Lv, c(-100, 1000))
chk_s3_class(Vp, "numeric")
chk_scalar(Vp)
chk_not_any_na(Vp)
chk_range(Vp, c(0, 100))
chk_s3_class(Llo, "numeric")
chk_scalar(Llo)
chk_not_any_na(Llo)
chk_range(Llo, c(0, 1000))
chk_s3_class(Lup, "numeric")
chk_scalar(Lup)
chk_not_any_na(Lup)
chk_range(Lup, c(0, 1000))
chk_s3_class(rho, "numeric")
chk_scalar(rho)
chk_not_any_na(rho)
chk_range(rho, c(0, 1))
chk_s3_class(Hm, "numeric")
chk_scalar(Hm)
chk_not_any_na(Hm)
chk_range(Hm, c(0, 1))
chk_s3_class(Nc, "numeric")
chk_scalar(Nc)
chk_not_any_na(Nc)
chk_range(Nc, c(0, 1))
chk_s3_class(Wa, "numeric")
chk_scalar(Wa)
chk_not_any_na(Wa)
chk_range(Wa, c(0.001, 0.1))
chk_s3_class(fa, "numeric")
chk_scalar(fa)
chk_not_any_na(fa)
chk_range(fa, c(1e-04, 100))
chk_s3_class(Rmax, "numeric")
chk_scalar(Rmax)
chk_not_any_na(Rmax)
chk_range(Rmax, c(1, 1e+06))
chk_s3_class(q, "numeric")
chk_scalar(q)
chk_not_any_na(q)
chk_range(q, c(0, 1))
chk_s3_class(RPR, "numeric")
chk_scalar(RPR)
chk_not_any_na(RPR)
chk_range(RPR, c(0, 100))
}
| /scratch/gouwar.j/cran-all/cranData/ypr/R/chk-parameters.R |
#' Adams Lake Bull Trout Population Parameters (2003)
#'
#' The population parameters for Bull Trout in Adams Lake from Bison et al
#' (2003)
#' @references Bison, R., O’Brien, D., and Martell, S.J.D. 2003. An Analysis of
#' Sustainable Fishing Options for Adams Lake Bull Trout Using Life History
#' and Telemetry Data. BC Ministry of Water Land and Air Protection, Kamloops,
#' B.C.
#' @format An object of class [ypr_population()].
#' @family data
#' @examples
#' adams_bt_03
#' ypr_plot_yield(adams_bt_03)
"adams_bt_03"
#' Chilliwack Lake Bull Trout Populations Parameters (2005)
#'
#' The populations parameters for Bull Trout in Chilliwack Lake from Taylor
#' (2005)
#'
#' @references Taylor, J.L. 2005. Sustainability of the Chilliwack Lake Char
#' Fishery. Ministry of Water, Land and Air Protection, Surrey, B.C.
#' @format An object of class [ypr_populations()].
#' @family populations
#' @family data
#' @examples
#' chilliwack_bt_05
#' yield <- ypr_tabulate_yield(chilliwack_bt_05, type = "optimal")
#' yield$pi <- round(yield$pi, 2)
#' yield <- yield[c("Llo", "Hm", "Rk", "pi")]
#' yield <- tidyr::spread(yield, Rk, pi)
#' yield <- yield[order(-yield$Hm), ]
#' yield
#' \dontrun{
#' ypr_plot_yield(chilliwack_bt_05, plot_values = FALSE) +
#' ggplot2::facet_grid(Rk ~ Hm) +
#' ggplot2::aes(group = Llo, linetype = Llo)
#' }
"chilliwack_bt_05"
#' Kootenay Lake Bull Trout Population Parameters (2013)
#'
#' The population parameters for Bull Trout in Kootenay Lake from Andrusak and
#' Thorley (2013)
#'
#' The estimates should not be used for management.
#' @references Andrusak, G.F., and Thorley, J.L. 2013. Kootenay Lake
#' Exploitation Study: Fishing and Natural Mortality of Large Rainbow Trout
#' and Bull Trout: 2013 Annual Report. A Poisson Consulting Ltd. and Redfish
#' Consulting Ltd. Report, Habitat Conservation Trust Foundation, Victoria,
#' BC.
#' @format An object of class [ypr_population()].
#' @family data
#' @examples
#' kootenay_bt_13
#' ypr_plot_yield(kootenay_bt_13)
"kootenay_bt_13"
#' Kootenay Lake Rainbow Trout Population Parameters (2013)
#'
#' The population parameters for Rainbow Trout in Kootenay Lake from Andrusak
#' and Thorley (2013)
#'
#' The estimates should not be used for management.
#' @references Andrusak, G.F., and Thorley, J.L. 2013. Kootenay Lake
#' Exploitation Study: Fishing and Natural Mortality of Large Rainbow Trout
#' and Bull Trout: 2013 Annual Report. A Poisson Consulting Ltd. and Redfish
#' Consulting Ltd. Report, Habitat Conservation Trust Foundation, Victoria,
#' BC.
#' @format An object of class [ypr_population()].
#' @family data
#' @examples
#' kootenay_rb_13
#' ypr_plot_yield(kootenay_rb_13)
"kootenay_rb_13"
#' Kootenay Lake Rainbow Trout Population Parameters
#'
#' The population parameters for Rainbow Trout in Kootenay Lake.
#'
#' The estimates are liable to change and should not be used for management.
#' @references Thorley, J.L., and Andrusak, G.F. 2017. The fishing and natural
#' mortality of large, piscivorous Bull Trout and Rainbow Trout in Kootenay
#' Lake, British Columbia (2008–2013). PeerJ 5: e2874. doi:10.7717/peerj.2874.
#' @format An object of class [ypr_population()].
#' @family data
#' @examples
#' kootenay_rb
#' ypr_plot_yield(kootenay_rb)
"kootenay_rb"
#' Quesnel Lake Bull Trout Population Parameters
#'
#' The population parameters for Bull Trout in Quesnel Lake, BC.
#'
#' The estimates are liable to change and should not be used for management.
#' @format An object of class [ypr_population()].
#' @family data
#' @examples
#' quesnel_bt
#' ypr_plot_yield(quesnel_bt)
"quesnel_bt"
#' Quesnel Lake Rainbow Trout Population Parameters
#'
#' The population parameters for Rainbow Trout in Quesnel Lake, BC.
#'
#' The estimates are liable to change and should not be used for management.
#' @format An object of class [ypr_population()].
#' @family data
#' @examples
#' quesnel_rb
#' ypr_plot_yield(quesnel_rb)
"quesnel_rb"
#' Quesnel Lake Lake Trout Population Parameters
#'
#' The population parameters for Lake Trout in Quesnel Lake, BC.
#'
#' The estimates are liable to change and should not be used for management.
#' @format An object of class [ypr_population()].
#' @family data
#' @examples
#' quesnel_lt
#' ypr_plot_yield(quesnel_lt)
"quesnel_lt"
| /scratch/gouwar.j/cran-all/cranData/ypr/R/data.R |
#' Detabulate Population Parameters
#'
#' @param x A data frame with columns Parameter and Value specifying one or more
#' parameters and their values.
#' @return An object of class [ypr_population()]
#' @family tabulate
#' @family parameters
#' @export
#' @examples
#' ypr_detabulate_parameters(ypr_tabulate_parameters(ypr_population()))
ypr_detabulate_parameters <- function(x) {
chk_s3_class(x, "data.frame")
chk_superset(colnames(x), c("Parameter", "Value"))
chk_s3_class(x$Parameter, "character")
chk_not_any_na(x$Parameter)
chk_subset(x$Parameter, parameters())
chk_unique(x$Parameter)
chk_numeric(x$Value)
chk_not_any_na(x$Value)
chk_range(x$Value, c(min(.parameters$Lower), max(.parameters$Upper)))
x <- merge(
x,
.parameters[c("Parameter", "Integer")],
by = "Parameter",
sort = FALSE
)
parameters <- as.list(x$Value)
names(parameters) <- x$Parameter
parameters <- mapply(function(x, y) if (y == 1) as.integer(x) else x,
parameters, x$Integer,
SIMPLIFY = FALSE
)
population <- do.call("ypr_population", parameters)
population
}
| /scratch/gouwar.j/cran-all/cranData/ypr/R/detabulate.R |
#' Create Ecotypes Object
#'
#' Creates an ypr_ecotypes object.
#'
#' @inheritParams params
#' @return An [ypr_ecotypes()] objects
#' @family ecotypes
#' @export
#' @examples
#' ypr_ecotypes(Linf = c(1, 2))
#' ypr_ecotypes(Linf = c(1, 2), t0 = c(0, 0.5))
ypr_ecotypes <- function(..., names = NULL) {
chk_null_or(names, vld = vld_character)
x <- ypr_populations(..., expand = FALSE, names = names)
x <- as_ypr_ecotypes(x)
if(is.null(names)) {
names <- ypr_names(x)
}
names(x) <- names
x
}
| /scratch/gouwar.j/cran-all/cranData/ypr/R/ecotypes.R |
#' Expand Populations
#'
#' An object of class [ypr_population()] of all unique combinations of parameter
#' values.
#'
#' @inheritParams params
#' @return An object of class `ypr_population`.
#' @family populations
#' @export
#' @examples
#' ypr_populations_expand(
#' ypr_populations(
#' Rk = c(2.5, 4, 2.5),
#' Hm = c(0.1, 0.2, 0.1)
#' )
#' )
ypr_populations_expand <- function(populations) {
populations <- as.data.frame(populations)
populations <- unique(populations)
populations <- as.list(populations)
populations <- lapply(populations, function(x) sort(unique(x)))
populations <- expand.grid(populations)
populations <- unique(populations)
as_ypr_populations(populations)
}
| /scratch/gouwar.j/cran-all/cranData/ypr/R/expand.R |
#' Exploitation Probability
#'
#' Converts capture probabilities into exploitation probabilities based on the
#' release and handling mortality probabilities where the probability of
#' exploitation includes handling mortalities. The calculation assumes that a
#' released fish cannot be recaught in the same year.
#'
#' In the case of no release (or 100% handling mortalities) the exploitation
#' probability is identical to the capture probability. Otherwise it is less.
#'
#' @inheritParams params
#' @param pi A vector of capture probabilities to calculate the exploitation
#' probabilities for.
#' @return A vector of exploitation probabilities.
#' @family calculate
#' @export
#' @examples
#' ypr_exploitation(ypr_population(pi = 0.4))
#' ypr_exploitation(ypr_population(pi = 0.4, rho = 0.6, Hm = 0.2))
ypr_exploitation <- function(object, pi = ypr_get_par(object)) {
chkor_vld(vld_is(object, "ypr_population"), vld_is(object, "ypr_ecotypes"))
chk_numeric(pi)
chk_not_any_na(pi)
chk_range(pi)
rho <- ypr_get_par(object, "rho")
Hm <- ypr_get_par(object, "Hm")
pi * (1 - rho) + pi * rho * Hm
}
| /scratch/gouwar.j/cran-all/cranData/ypr/R/exploitation.R |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.