#------------------------------------------------------------------------------------------------
# Rugby Europe Championship 2020
REC <- read.csv("D:/RFU/Tier_2_3/REC2020/T2data.csv", header=TRUE, sep = ";")
#------------------------------------------------------------------------------------------------
# Moving Forwards as % ot total possessions
OwnFor <- REC$F/REC$Poss
#------------------------------------------------------------------------------------------------
# Opponent Stats (Defence: How the opponent moved across the vertical zones)
Forwards <- NULL
NotMoving <- NULL
Backwards <- NULL
Opp_T_Pos <- NULL
OppPenOff <- NULL
for(i in 1:NROW(REC)){
Forwards[i] <- REC$F[which(REC$Team == REC$Opp[i] & REC$Round == REC$Round[i])]
NotMoving[i] <- REC$NM[which(REC$Team == REC$Opp[i] & REC$Round == REC$Round[i])]
Backwards[i] <- REC$B[which(REC$Team == REC$Opp[i] & REC$Round == REC$Round[i])]
Opp_T_Pos[i] <- Forwards[i] + NotMoving[i] + Backwards[i]
OppPenOff[i] <- REC$PenOff[which(REC$Team == REC$Opp[i] & REC$Round == REC$Round[i])]
}
#------------------------------------------------------------------------------------------------
# Descriptive Stats
median(REC$TryC) # median
DescTools::Mode(REC$TryC) # mode
mean(REC$TryC) # aritmetic average
sd(REC$TryC) # std.deviation
median(REC$PtsC) # median
DescTools::Mode(REC$PtsC) # mode
mean(REC$PtsC) # aritmetic average
sd(REC$PtsC) # std.deviation
#------------------------------------------------------------------------------------------------
# Colours
BEL_C1 <- "#000000"; BEL_C2 <- "#FDDA24"; ESP_C1 <- "#AA151B"; ESP_C2 <- "#F1BF00"
GEO_C1 <- "#FF0000"; GEO_C2 <- "#FFFFFF"; POR_C1 <- "#006600"; POR_C2 <- "#FF0000"
ROM_C1 <- "#002B7F"; ROM_C2 <- "#FCD116"; RUS_C1 <- "#D00B0E"; RUS_C2 <- "#0039A6"
ColTea <- data.frame(c("BEL", "ESP", "GEO", "POR", "ROM", "RUS"),
c(BEL_C1, ESP_C1, GEO_C1, POR_C1, ROM_C1, RUS_C1),
c(BEL_C2, ESP_C2, GEO_C2, POR_C2, ROM_C2, RUS_C2))
colnames(ColTea) <- c("Team", "Col1", "Col2")
#------------------------------------------------------------------------------------------------
# Offence: Graph
ForTRY <- plot_ly()
ForPTS <- plot_ly()
for(i in 1:NROW(unique(REC$Team))){
ForTRY <- add_trace(ForTRY,
x = OwnFor[which(REC$Team == unique(REC$Team)[i])],
y = REC$Try[which(REC$Team == unique(REC$Team)[i])],
type = "scatter", mode = "markers", name = unique(REC$Team)[i], hoverinfo = "text",
text = paste(REC$Round[which(REC$Team == unique(REC$Team)[i])],
"
Opponent: ", REC$Opp[which(REC$Team == unique(REC$Team)[i])],
"
Result: ", REC$Pts[which(REC$Team == unique(REC$Team)[i])], "-",
REC$PtsC[which(REC$Team == unique(REC$Team)[i])],
"
Tries scored: ", REC$Try[which(REC$Team == unique(REC$Team)[i])],
"
Moving forwards: ", round(OwnFor[which(REC$Team == unique(REC$Team)[i])]*100,1), "%",
sep = ""),
legendgroup = unique(REC$Team)[i], showlegend = TRUE,
marker = list(size = 16,
color = ColTea$Col1[which(ColTea$Team == unique(REC$Team)[i])],
line = list(width = 1.5,
color = ColTea$Col2[which(ColTea$Team == unique(REC$Team)[i])])))
ForPTS <- add_trace(ForPTS,
x = OwnFor[which(REC$Team == unique(REC$Team)[i])],
y = REC$Pts[which(REC$Team == unique(REC$Team)[i])],
type = "scatter", mode = "markers", name = unique(REC$Team)[i], hoverinfo = "text",
text = paste(REC$Round[which(REC$Team == unique(REC$Team)[i])],
"
Opponent: ", REC$Opp[which(REC$Team == unique(REC$Team)[i])],
"
Result: ", REC$Pts[which(REC$Team == unique(REC$Team)[i])], "-",
REC$PtsC[which(REC$Team == unique(REC$Team)[i])],
"
Tries scored: ", REC$Try[which(REC$Team == unique(REC$Team)[i])],
"
Moving forwards: ", round(OwnFor[which(REC$Team == unique(REC$Team)[i])]*100,1), "%",
sep = ""),
legendgroup = unique(REC$Team)[i], showlegend = FALSE,
marker = list(size = 16,
color = ColTea$Col1[which(ColTea$Team == unique(REC$Team)[i])],
line = list(width = 1.5,
color = ColTea$Col2[which(ColTea$Team == unique(REC$Team)[i])])))
}
subplot(
ForTRY %>%
add_trace(x = median(OwnFor),
y = seq(min(REC$Try), max(REC$Try), length.out = 222),
type = "scatter", mode = "lines", inherit = FALSE, hoverinfo = "text",
text = paste("Median: ", round(median(OwnFor)*100,1), "%", sep = ""),
line = list(color = "red", dash = "dash", width = 0.5), showlegend = FALSE) %>%
add_trace(x = seq(min(OwnFor), max(OwnFor), length.out = 222),
y = median(REC$Try),
type = "scatter", mode = "lines", inherit = FALSE, hoverinfo = "text",
text = paste("Median: ", median(REC$Try), sep = ""),
line = list(color = "red", dash = "dash", width = 0.5), showlegend = FALSE),
ForPTS %>%
add_trace(x = median(OwnFor),
y = seq(min(REC$Pts), max(REC$Pts), length.out = 222),
type = "scatter", mode = "lines", inherit = FALSE, hoverinfo = "text",
text = paste("Median: ", round(median(OwnFor)*100,1), "%", sep = ""),
line = list(color = "red", dash = "dash", width = 0.5), showlegend = FALSE) %>%
add_trace(x = seq(min(OwnFor), max(OwnFor), length.out = 222),
y = median(REC$Pts),
type = "scatter", mode = "lines", inherit = FALSE, hoverinfo = "text",
text = paste("Median: ", median(REC$Pts), sep = ""),
line = list(color = "red", dash = "dash", width = 0.5), showlegend = FALSE),
nrows = 1, margin = 0.05
) %>%
layout(title = "Moving Forwards and Scoring Tries and Points", titlefont = list(color = "white"),
xaxis = list(title = "% of Possession When Ball Travelled Forwards", tickformat = "%",
titlefont = list(color = "white"), tickfont = list(color = "rgb(102,102,102)"),
gridcolor = "rgb(22,22,22)", gridwidth = 0.5),
yaxis = list(title = "Tries Scored", titlefont = list(color = "white"), zeroline = FALSE,
tickfont = list(color = "rgb(102,102,102)"), gridcolor = "rgb(22,22,22)", gridwidth = 0.5),
xaxis2 = list(title = "% of Possession When Ball Travelled Forwards", tickformat = "%",
titlefont = list(color = "white"), tickfont = list(color = "rgb(102,102,102)"),
gridcolor = "rgb(22,22,22)", gridwidth = 0.5),
yaxis2 = list(title = "Points Scored", titlefont = list(color = "white"), zeroline = FALSE,
tickfont = list(color = "rgb(102,102,102)"), gridcolor = "rgb(22,22,22)", gridwidth = 0.5),
plot_bgcolor = "black", paper_bgcolor = "black",
margin = list(b = 150, t = 150, l = 150, r = 150, pad = 1))
#------------------------------------------------------------------------------------------------
# Defence: Graph
Tries_con <-
plot_ly(x = (NotMoving+Backwards)/Opp_T_Pos,
y = REC$TryC,
type = "scatter", mode = "markers", hoverinfo = "text",
size = REC$TryC-REC$Try, sizes = c(6, 22),
marker = list(sizemode = "diameter", color = "rgb(0,51,153)",
line = list(width = 1.5, color = "rgb(255,204,0)")),
text = paste(REC$Team, " (", REC$Round, ")", "
Opponent: ", REC$Opp,
"
Result: ", REC$Pts, "-", REC$PtsC, " (", ifelse(REC$Pts>REC$PtsC, "W", "L"), ")",
"
Tries conceded: ", REC$TryC,
"
Opp. not moving forwards: ", round((NotMoving+Backwards)/Opp_T_Pos*100,1), "%",
sep = "")) %>%
add_trace(x = median((NotMoving+Backwards)/Opp_T_Pos),
y = seq(min(REC$TryC), max(REC$TryC), length.out = 222),
type = "scatter", mode = "lines", inherit = FALSE, hoverinfo = "text",
text = paste("Median: ", round(median((NotMoving+Backwards)/Opp_T_Pos)*100,1), "%", sep = ""),
line = list(color = "red", dash = "dash", width = 0.5)) %>%
add_trace(x = seq(min((NotMoving+Backwards)/Opp_T_Pos), max((NotMoving+Backwards)/Opp_T_Pos), length.out = 222),
y = median(REC$TryC),
type = "scatter", mode = "lines", inherit = FALSE, hoverinfo = "text",
text = paste("Median: ", median(REC$TryC), sep = ""),
line = list(color = "red", dash = "dash", width = 0.5))
Pts_con <-
plot_ly(x = (NotMoving+Backwards)/Opp_T_Pos,
y = REC$PtsC,
type = "scatter", mode = "markers", hoverinfo = "text",
size = REC$PtsC-REC$Pts, sizes = c(6, 22),
marker = list(sizemode = "diameter", color = "rgb(0,51,153)", line = list(width = 1.5, color = "rgb(255,204,0)")),
text = paste(REC$Team, " (", REC$Round, ")", "
Opponent: ", REC$Opp,
"
Result: ", REC$Pts, "-", REC$PtsC, " (", ifelse(REC$Pts>REC$PtsC, "W", "L"), ")",
"
Tries conceded: ", REC$TryC,
"
Opp. not moving forwards: ", round((NotMoving+Backwards)/Opp_T_Pos*100,1), "%",
sep = ""))%>%
add_trace(x = median((NotMoving+Backwards)/Opp_T_Pos),
y = seq(min(REC$PtsC), max(REC$PtsC), length.out = 222),
type = "scatter", mode = "lines", inherit = FALSE, hoverinfo = "text",
text = paste("Median: ", round(median((NotMoving+Backwards)/Opp_T_Pos)*100,1), "%", sep = ""),
line = list(color = "red", dash = "dash", width = 0.5)) %>%
add_trace(x = seq(min((NotMoving+Backwards)/Opp_T_Pos), max((NotMoving+Backwards)/Opp_T_Pos), length.out = 222),
y = median(REC$PtsC),
type = "scatter", mode = "lines", inherit = FALSE, hoverinfo = "text",
text = paste("Median: ", median(REC$PtsC), sep = ""),
line = list(color = "red", dash = "dash", width = 0.5))
subplot(
Tries_con, Pts_con,
nrows = 1, margin = 0.05
) %>%
layout(title = "Preventing Opponents From Moving Forwards and Conceding Tries and Points", titlefont = list(color = "white"),
xaxis = list(title = "% of Opp. Possession without Moving Forwards", tickformat = "%",
titlefont = list(color = "white"), tickfont = list(color = "rgb(102,102,102)"),
gridcolor = "rgb(22,22,22)", gridwidth = 0.5),
xaxis2 = list(title = "% of Opp. Possession without Moving Forwards", tickformat = "%",
titlefont = list(color = "white"), tickfont = list(color = "rgb(102,102,102)"),
gridcolor = "rgb(22,22,22)", gridwidth = 0.5),
yaxis = list(title = "Tries Conceded", zeroline = FALSE, titlefont = list(color = "white"),
tickfont = list(color = "rgb(102,102,102)"), gridcolor = "rgb(22,22,22)", gridwidth = 0.5),
yaxis2 = list(title = "Points Conceded", zeroline = FALSE, titlefont = list(color = "white"),
tickfont = list(color = "rgb(102,102,102)"), gridcolor = "rgb(22,22,22)", gridwidth = 0.5),
showlegend = FALSE, margin = list(b = 150, t = 150, l = 150, r = 150, pad = 1),
plot_bgcolor = "black", paper_bgcolor = "black") %>%
add_annotations(text = "Bubbles' size determined by the difference between tries (points) conceded and tries (points) scored",
showarrow = FALSE, xref = "paper", yref = "paper", x = -0.05, y = -0.15)