Rows: 83 Columns: 35
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
chr (24): Category, TA Kickout Location, Half, TB Kickout Location, Quarter...
dbl (1): N#
num (2): X, Y
lgl (4): All, TB Origin of Scores, EMPTY CAT, Ungroup
time (4): Start, Click, End, Duration
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
View(Test_again)library(showtext)
Warning: package 'showtext' was built under R version 4.3.3
Loading required package: sysfonts
Warning: package 'sysfonts' was built under R version 4.3.3
Loading required package: showtextdb
Warning: package 'showtextdb' was built under R version 4.3.3
draw_gaa_pitch_portrait <-function() {# Define pitch dimensions pitch_length <-145# Maximum length in meters pitch_width <-90# Maximum width in meters# Define six-yard box dimensions six_yard_box_length <-14# Length (x-direction) six_yard_box_width <-4.5# Width (y-direction)# Create base pitch pitch <-ggplot() +# Pitch outlinegeom_rect(aes(xmin =0, xmax = pitch_width, ymin =0, ymax = pitch_length), fill ="slateblue4", color ="white", size =1) +# Six-yard boxesgeom_rect(aes(xmin = (pitch_width - six_yard_box_length) /2, xmax = (pitch_width + six_yard_box_length) /2, ymin =0, ymax = six_yard_box_width), fill =NA, color ="white", size =1) +# Bottom six-yard boxgeom_rect(aes(xmin = (pitch_width - six_yard_box_length) /2, xmax = (pitch_width + six_yard_box_length) /2, ymin = pitch_length - six_yard_box_width, ymax = pitch_length), fill =NA, color ="white", size =1) +# Top six-yard box# Goal areasgeom_rect(aes(xmin =35, xmax =55, ymin =0, ymax =14), fill =NA, color ="white", size =1) +geom_rect(aes(xmin =35, xmax =55, ymin = pitch_length -14, ymax = pitch_length), fill =NA, color ="white", size =1) +# Halfway linegeom_segment(aes(x =0, xend = pitch_width, y = pitch_length /2, yend = pitch_length /2), color ="white", size =1, linetype ="dashed") +# 13m, 21m, 45m, 65m linesgeom_segment(aes(x =0, xend = pitch_width, y =14, yend =14), color ="white", size =1) +# Bottom 13m linegeom_segment(aes(x =0, xend = pitch_width, y = pitch_length -14, yend = pitch_length -14), color ="white", size =1) +# Top 13m linegeom_segment(aes(x =0, xend = pitch_width, y =21, yend =21), color ="white", size =1) +# Bottom 21m linegeom_segment(aes(x =0, xend = pitch_width, y = pitch_length -21, yend = pitch_length -21), color ="white", size =1) +# Top 21m linegeom_segment(aes(x =0, xend = pitch_width, y =45, yend =45), color ="white", size =1) +# Bottom 45m linegeom_segment(aes(x =0, xend = pitch_width, y = pitch_length -45, yend = pitch_length -45), color ="white", size =1) +# Top 45m linegeom_segment(aes(x =0, xend = pitch_width, y =65, yend =65), color ="white", size =1) +# Bottom 65m linegeom_segment(aes(x =0, xend = pitch_width, y = pitch_length -65, yend = pitch_length -65), color ="white", size =1) +# Top 65m line# Existing arcs (x = 45)annotate("path", x =45+15*cos(seq(pi, 0, length.out =100)), y =21+13*sin(seq(pi, 0, length.out =100)), color ="white", size =1) +# Bottom arcannotate("path", x =45+15*cos(seq(pi, 2* pi, length.out =100)), y = pitch_length -21+13*sin(seq(pi, 2* pi, length.out =100)), color ="white", size =1) +# Top arc# New 40-meter arcsannotate("path", x =45+40*cos(seq(pi, 0, length.out =100)), y =21+19*sin(seq(pi, 0, length.out =100)), color ="white", size =1) +# Bottom 40m arcannotate("path", x =45+40*cos(seq(pi, 2* pi, length.out =100)), y = pitch_length -21+19*sin(seq(pi, 2* pi, length.out =100)), color ="white", size =1) +# Top 40m arc# Text Labelsannotate("text", x =8, y =43, label ="Own 45", color ="white", size =3) +# Label bottom 45m lineannotate("text", x =8, y =63, label ="Own 65", color ="white", size =3) +# Label bottom 65m lineannotate("text", x =7.5, y = pitch_length -60, label ="Opp 65", color ="white", size =3) +# Label top 65m lineannotate("text", x =7.5, y = pitch_length -41, label ="Opp 45", color ="white", size =3) +# Label top 45m line# Set themetheme_void() +theme(panel.background =element_rect(fill ="slateblue4", color =NA),plot.background =element_rect(fill ="slateblue4", color =NA),plot.margin =margin(0, 0, 0, 0)) +coord_fixed(ratio =1) # Ensure equal proportionsprint(pitch)}# Draw the GAA pitch without the titledraw_gaa_pitch_portrait()
Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
ℹ Please use `linewidth` instead.
draw_takickout_drawing <-function() {# Define pitch dimensions pitch_length <-105# Pitch length ends at 100 meters pitch_width <-90# Maximum width in meters# Define six-yard box dimensions six_yard_box_length <-14# Length (x-direction) six_yard_box_width <-4.5# Width (y-direction)# Create base pitch pitch <-ggplot() +# Pitch outlinegeom_rect(aes(xmin =0, xmax = pitch_width, ymin =0, ymax = pitch_length), fill ="slateblue4", color ="white", size =1) +# Six-yard boxgeom_rect(aes(xmin = (pitch_width - six_yard_box_length) /2, xmax = (pitch_width + six_yard_box_length) /2, ymin =0, ymax = six_yard_box_width), fill =NA, color ="white", size =1) +# Bottom six-yard box# Goal areasgeom_rect(aes(xmin =35, xmax =55, ymin =0, ymax =14), fill =NA, color ="white", size =1) +# 13m, 21m, 45m, 65m, Opponent's 65m, and 100m linesgeom_segment(aes(x =0, xend = pitch_width, y =14, yend =14), color ="white", size =1) +# 13m linegeom_segment(aes(x =0, xend = pitch_width, y =21, yend =21), color ="white", size =1) +# 21m linegeom_segment(aes(x =0, xend = pitch_width, y =45, yend =45), color ="white", size =1) +# 45m linegeom_segment(aes(x =0, xend = pitch_width, y =65, yend =65), color ="white", size =1) +# Own 65m linegeom_segment(aes(x =0, xend = pitch_width, y =72.5, yend =72.5), color ="white", size =1, linetype ="dashed") +# Halfway linegeom_segment(aes(x =0, xend = pitch_width, y =80, yend =80), color ="white", size =1) +# Opponent's 65m linegeom_segment(aes(x =0, xend = pitch_width, y =100, yend =100), color ="white", size =1) +# 100m line# Existing arcsannotate("path", x = pitch_width /2+15*cos(seq(pi, 0, length.out =100)), y =21+13*sin(seq(pi, 0, length.out =100)), color ="white", size =1) +# Bottom arcannotate("path", x = pitch_width /2+40*cos(seq(pi, 0, length.out =100)), y =21+19*sin(seq(pi, 0, length.out =100)), color ="white", size =1) +# 40m arc# Text Labelsannotate("text", x =6.5, y =43, label ="Own 45", color ="white", size =3.5) +# Label 45m lineannotate("text", x =6.5, y =63, label ="Own 65", color ="white", size =3.5) +# Label 65m lineannotate("text", x =6, y =103, label ="Opp 45", color ="white", size =3.5) +# Label 100m lineannotate("text", x =6, y =83, label ="Opp 65", color ="white", size =3.5) +# Label Opponent's 65m line# Set themetheme_void() +theme(panel.background =element_rect(fill ="slateblue4", color =NA),plot.background =element_rect(fill ="slateblue4", color =NA),plot.margin =margin(0, 0, 0, 0)) +coord_fixed(ratio =1) # Ensure equal proportionsprint(pitch)}# Draw the updated pitchdraw_takickout_drawing()
draw_tbkickout_drawing <-function() {# Define pitch dimensions pitch_length <-105# Pitch length ends at 100 meters pitch_width <-90# Maximum width in meters# Define six-yard box dimensions six_yard_box_length <-14# Length (x-direction) six_yard_box_width <-4.5# Width (y-direction)# Create base pitch pitch <-ggplot() +# Pitch outlinegeom_rect(aes(xmin =0, xmax = pitch_width, ymin =0, ymax = pitch_length), fill ="slateblue4", color ="white", size =1) +# Six-yard boxgeom_rect(aes(xmin = (pitch_width - six_yard_box_length) /2, xmax = (pitch_width + six_yard_box_length) /2, ymin =0, ymax = six_yard_box_width), fill =NA, color ="white", size =1) +# Bottom six-yard box# Goal areasgeom_rect(aes(xmin =35, xmax =55, ymin =0, ymax =14), fill =NA, color ="white", size =1) +# 13m, 21m, 45m, 65m, Opponent's 65m, and 100m linesgeom_segment(aes(x =0, xend = pitch_width, y =14, yend =14), color ="white", size =1) +# 13m linegeom_segment(aes(x =0, xend = pitch_width, y =21, yend =21), color ="white", size =1) +# 21m linegeom_segment(aes(x =0, xend = pitch_width, y =45, yend =45), color ="white", size =1) +# 45m linegeom_segment(aes(x =0, xend = pitch_width, y =65, yend =65), color ="white", size =1) +# Own 65m linegeom_segment(aes(x =0, xend = pitch_width, y =72.5, yend =72.5), color ="white", size =1, linetype ="dashed") +# Halfway linegeom_segment(aes(x =0, xend = pitch_width, y =80, yend =80), color ="white", size =1) +# Opponent's 65m linegeom_segment(aes(x =0, xend = pitch_width, y =100, yend =100), color ="white", size =1) +# 100m line# Existing arcsannotate("path", x = pitch_width /2+15*cos(seq(pi, 0, length.out =100)), y =21+13*sin(seq(pi, 0, length.out =100)), color ="white", size =1) +# Bottom arcannotate("path", x = pitch_width /2+40*cos(seq(pi, 0, length.out =100)), y =21+19*sin(seq(pi, 0, length.out =100)), color ="white", size =1) +# 40m arc# Text Labelsannotate("text", x =6.5, y =43, label ="Own 45", color ="white", size =3.5) +# Label 45m lineannotate("text", x =6.5, y =63, label ="Own 65", color ="white", size =3.5) +# Label 65m lineannotate("text", x =6, y =103, label ="Opp 45", color ="white", size =3.5) +# Label 100m lineannotate("text", x =6, y =83, label ="Opp 65", color ="white", size =3.5) +# Label Opponent's 65m line# Set themetheme_void() +theme(panel.background =element_rect(fill ="slateblue4", color =NA),plot.background =element_rect(fill ="slateblue4", color =NA),plot.margin =margin(0, 0, 0, 0)) +coord_fixed(ratio =1) # Ensure equal proportionsprint(pitch)}# Draw the updated pitchdraw_tbkickout_drawing()
draw_ta_shots <-function() {# Define pitch dimensions for the top third pitch_length <-145# Maximum length of the full pitch pitch_width <-90# Maximum width of the pitch start_y <-75# Start of the top third end_y <-145# End of the top third# Define six-yard box dimensions six_yard_box_length <-14# Length (x-direction) six_yard_box_width <-4.5# Width (y-direction)# Create base pitch pitch <-ggplot() +# Pitch outline for the top thirdgeom_rect(aes(xmin =0, xmax = pitch_width, ymin = start_y, ymax = end_y), fill ="slateblue4", color ="white", size =1) +geom_rect(aes(xmin = (pitch_width - six_yard_box_length) /2, xmax = (pitch_width + six_yard_box_length) /2, ymin = pitch_length - six_yard_box_width, ymax = pitch_length), fill =NA, color ="white", size =1) +# Top six-yard box# Goal areasgeom_rect(aes(xmin =35, xmax =55, ymin = pitch_length -14, ymax = pitch_length), fill =NA, color ="white", size =1) +# 13m, 21m, and 45m lines within the top thirdgeom_segment(aes(x =0, xend = pitch_width, y = end_y -14, yend = end_y -14), color ="white", size =1) +# 13m linegeom_segment(aes(x =0, xend = pitch_width, y = end_y -21, yend = end_y -21), color ="white", size =1) +# 21m linegeom_segment(aes(x =0, xend = pitch_width, y = end_y -45, yend = end_y -45), color ="white", size =1) +# 45m linegeom_segment(aes(x =0, xend = pitch_width, y = start_y, yend = start_y), color ="white", size =1) +# Bottom boundary of the top third# Arc at the top goal areaannotate("path", x = pitch_width /2+15*cos(seq(pi, 2* pi, length.out =100)), y = end_y -21+13*sin(seq(pi, 2* pi, length.out =100)), color ="white", size =1) +# Top 21m arcannotate("path", x = pitch_width /2+40*cos(seq(pi, 2* pi, length.out =100)), y = end_y -21+19*sin(seq(pi, 2* pi, length.out =100)), color ="white", size =1) +# Top 40m arc# Text Labelsannotate("text", x =4.5, y = end_y -43, label ="Opp 45", color ="white", size =4) +# Label 45m lineannotate("text", x =4.5, y = end_y -68, label ="Opp 65", color ="white", size =4) +# Label 65m line# Set themetheme_void() +theme(panel.background =element_rect(fill ="slateblue4", color =NA),plot.background =element_rect(fill ="slateblue4", color =NA),plot.margin =margin(0, 0, 0, 0)) +coord_fixed(ratio =1, xlim =c(0, pitch_width), ylim =c(start_y, end_y)) # Focus on the top third onlyprint(pitch)}# Draw the pitch for the top thirddraw_ta_shots()
draw_tb_shots <-function() {# Define pitch dimensions for the top third pitch_length <-145# Maximum length of the full pitch pitch_width <-90# Maximum width of the pitch start_y <-75# Start of the top third end_y <-145# End of the top third# Define six-yard box dimensions six_yard_box_length <-14# Length (x-direction) six_yard_box_width <-4.5# Width (y-direction)# Create base pitch pitch <-ggplot() +# Pitch outline for the top thirdgeom_rect(aes(xmin =0, xmax = pitch_width, ymin = start_y, ymax = end_y), fill ="slateblue4", color ="white", size =1) +geom_rect(aes(xmin = (pitch_width - six_yard_box_length) /2, xmax = (pitch_width + six_yard_box_length) /2, ymin = pitch_length - six_yard_box_width, ymax = pitch_length), fill =NA, color ="white", size =1) +# Top six-yard box# Goal areasgeom_rect(aes(xmin =35, xmax =55, ymin = pitch_length -14, ymax = pitch_length), fill =NA, color ="white", size =1) +# 13m, 21m, and 45m lines within the top thirdgeom_segment(aes(x =0, xend = pitch_width, y = end_y -14, yend = end_y -14), color ="white", size =1) +# 13m linegeom_segment(aes(x =0, xend = pitch_width, y = end_y -21, yend = end_y -21), color ="white", size =1) +# 21m linegeom_segment(aes(x =0, xend = pitch_width, y = end_y -45, yend = end_y -45), color ="white", size =1) +# 45m linegeom_segment(aes(x =0, xend = pitch_width, y = start_y, yend = start_y), color ="white", size =1) +# Bottom boundary of the top third# Arc at the top goal areaannotate("path", x = pitch_width /2+15*cos(seq(pi, 2* pi, length.out =100)), y = end_y -21+13*sin(seq(pi, 2* pi, length.out =100)), color ="white", size =1) +# Top 21m arcannotate("path", x = pitch_width /2+40*cos(seq(pi, 2* pi, length.out =100)), y = end_y -21+19*sin(seq(pi, 2* pi, length.out =100)), color ="white", size =1) +# Top 40m arc# Text Labelsannotate("text", x =4.5, y = end_y -43, label ="Opp 45", color ="white", size =4) +# Label 45m lineannotate("text", x =4.5, y = end_y -68, label ="Opp 65", color ="white", size =4) +# Label 65m line# Set themetheme_void() +theme(panel.background =element_rect(fill ="slateblue4", color =NA),plot.background =element_rect(fill ="slateblue4", color =NA),plot.margin =margin(0, 0, 0, 0)) +coord_fixed(ratio =1, xlim =c(0, pitch_width), ylim =c(start_y, end_y)) # Focus on the top third onlyprint(pitch)}# Draw the pitch for the top thirddraw_tb_shots()
# Assuming 'Test_again' dataset is already loaded in your environment# Count occurrences of "TA Kickout" and "TB Kickout"ta_kickout_count <-sum(Test_again$Kickouts =="TA Kickout", na.rm =TRUE)tb_kickout_count <-sum(Test_again$Kickouts =="TB Kickout", na.rm =TRUE)# Add them together to get the totaltotal_kickouts <- ta_kickout_count + tb_kickout_count# Print the resultscat("KER Kickouts:", ta_kickout_count, "\n")
KER Kickouts: 1
cat("OPP Kickouts:", tb_kickout_count, "\n")
OPP Kickouts: 1
cat("Total Kickouts:", total_kickouts, "\n")
Total Kickouts: 2
# Assuming 'Test_again' dataset is already loaded# Count the occurrences where "TA Short" appears in the TA Kickout Location column# and "TA Won" appears in the Kickout Outcome columnta_short_won_count <-sum(Test_again$`TA Kickout Location`=="TA SKO"& Test_again$`Kickout Outcome`=="TA Won", na.rm =TRUE)# Count the occurrences where "TA Short" appears in the TA Kickout Location column# and "TA Lost" appears in the Kickout Outcome columnta_short_lost_count <-sum(Test_again$`TA Kickout Location`=="TA SKO"& Test_again$`Kickout Outcome`=="TA Lost", na.rm =TRUE)# Count the occurrences where "TA Long" appears in the TA Kickout Location column# and "TA Won" appears in the Kickout Outcome columnta_long_won_count <-sum(Test_again$`TA Kickout Location`=="TA LKO"& Test_again$`Kickout Outcome`=="TA Won", na.rm =TRUE)# Count the occurrences where "TA Long" appears in the TA Kickout Location column# and "TA Lost" appears in the Kickout Outcome columnta_long_lost_count <-sum(Test_again$`TA Kickout Location`=="TA LKO"& Test_again$`Kickout Outcome`=="TA Lost", na.rm =TRUE)# Total Short count (Won + Lost)total_short_count <- ta_short_won_count + ta_short_lost_count# Total Long count (Won + Lost)total_long_count <- ta_long_won_count + ta_long_lost_count# Calculate total kickouts wontotal_kickouts_won <- ta_short_won_count + ta_long_won_count# Calculate total kickouts takentotal_kickouts_taken <- total_short_count + total_long_count# Calculate win percentagewin_percentage <- (total_kickouts_won / total_kickouts_taken) *100# Create a data frame for the table without the Total columnkickouts_table <-data.frame(KER =c("Won", "Lost", "Total"), # Rename the Outcome column to KERShort =c(ta_short_won_count, ta_short_lost_count, total_short_count), # Renamed Short to ShrtLong =c(ta_long_won_count, ta_long_lost_count, total_long_count) # Renamed Long Kickouts column)# Load knitr and kableExtra for creating the tablelibrary(knitr)library(kableExtra)# Render the table with color and titles, centered contentkable(kickouts_table, col.names =c("KER", "Short", "Long"),format ="html", align ="c") %>%# Center-align all columnskable_styling(bootstrap_options =c("striped", "hover"), full_width = F) %>%column_spec(1, color ="black", background ="white") %>%column_spec(2, color ="black", background ="white") %>%column_spec(3, color ="black", background ="white") %>%row_spec(0, background ="#28a745", color ="white", bold =TRUE) # Highlight top row (column headers) in green
KER
Short
Long
Won
1
0
Lost
0
0
Total
1
0
# Print the win percentage and total informationcat("KER KO Won:", round(win_percentage, 2), "%", "(", total_kickouts_won, "/", total_kickouts_taken, ")\n")
KER KO Won: 100 % ( 1 / 1 )
# Assuming 'Test_again' dataset is already loaded# Count the occurrences where "TB Short" appears in the TB Kickout Location column# and "TA Won" appears in the Kickout Outcome columntb_short_won_count <-sum(Test_again$`TB Kickout Location`=="TB SKO"& Test_again$`Kickout Outcome`=="TA Won", na.rm =TRUE)# Count the occurrences where "TB Short" appears in the TB Kickout Location column# and "TB Lost" appears in the Kickout Outcome columntb_short_lost_count <-sum(Test_again$`TB Kickout Location`=="TB SKO"& Test_again$`Kickout Outcome`=="TA Lost", na.rm =TRUE)# Count the occurrences where "TB Long" appears in the TB Kickout Location column# and "TB Won" appears in the Kickout Outcome columntb_long_won_count <-sum(Test_again$`TB Kickout Location`=="TB LKO"& Test_again$`Kickout Outcome`=="TA Won", na.rm =TRUE)# Count the occurrences where "TB Long" appears in the TB Kickout Location column# and "TB Lost" appears in the Kickout Outcome columntb_long_lost_count <-sum(Test_again$`TB Kickout Location`=="TB LKO"& Test_again$`Kickout Outcome`=="TA Lost", na.rm =TRUE)# Total Short count (Won + Lost)total_tb_short_count <- tb_short_won_count + tb_short_lost_count# Total Long count (Won + Lost)total_tb_long_count <- tb_long_won_count + tb_long_lost_count# Total kickouts wontotal_tb_kickouts_won <- tb_short_won_count + tb_long_won_count# Total kickouts takentotal_tb_kickouts_taken <- total_tb_short_count + total_tb_long_count# Calculate win percentageopp_win_percentage <- (total_tb_kickouts_won / total_tb_kickouts_taken) *100# Load knitr for creating the tablelibrary(knitr)# Create a data frame for the table with separate columns for Short and Long Kickoutskickouts_table_opposite <-data.frame(OPP =c("Won", "Lost", "Total"), # Rename the Outcome column to OPPShort =c(tb_short_won_count, tb_short_lost_count, total_tb_short_count), # Renamed Short to ShortLong =c(tb_long_won_count, tb_long_lost_count, total_tb_long_count) # Renamed Long Kickouts column)# Render the table with color and titles, centered contentkable(kickouts_table_opposite, col.names =c("OPP", "Short", "Long"),format ="markdown", align ="c") %>%# Center-align all columnskable_styling(bootstrap_options =c("striped", "hover"), full_width = F) %>%column_spec(1, color ="black", background ="white") %>%column_spec(2, color ="black", background ="white") %>%column_spec(3, color ="black", background ="white") %>%row_spec(0, background ="black", color ="white", bold =TRUE) # Highlight top row (column headers) in black
OPP
Short
Long
Won
0
0
Lost
1
0
Total
1
0
# Print the win percentage and total informationcat("OPP KO Won:", round(opp_win_percentage, 2), "%", "(", total_tb_kickouts_won, "/", total_tb_kickouts_taken, ")\n")
OPP KO Won: 0 % ( 0 / 1 )
# Initialize countersta_clean_won <-0ta_clean_lost <-0ta_break_won <-0ta_break_lost <-0# Loop through the dataset to calculate countsfor (i in2:nrow(Test_again)) { # Start from the second rowif (!is.na(Test_again$Kickouts[i -1]) && Test_again$Kickouts[i -1] =="TA Kickout") { if (Test_again$`TA Won Kickout Breakdown`[i] =="TA Clean") { ta_clean_won <- ta_clean_won +1 } elseif (Test_again$`TA Won Kickout Breakdown`[i] =="TB Clean") { ta_clean_lost <- ta_clean_lost +1 } elseif (Test_again$`TA Won Kickout Breakdown`[i] =="TA Break") { ta_break_won <- ta_break_won +1 } elseif (Test_again$`TA Won Kickout Breakdown`[i] =="TB Break") { ta_break_lost <- ta_break_lost +1 } }}# Calculate totalstotal_clean <- ta_clean_won + ta_clean_losttotal_break <- ta_break_won + ta_break_lost# Create a data frame with KER, Clean, and Break as columnstable_data <-data.frame(KER =c("Won", "Lost", "Total"),Clean =c(ta_clean_won, ta_clean_lost, total_clean),Break =c(ta_break_won, ta_break_lost, total_break))# Load knitr and kableExtra for table stylinglibrary(knitr)library(kableExtra)# Render the table with the correct layoutkable(table_data, col.names =c("KER", "Clean", "Break"), # Set the column headersformat ="html", align ="c") %>%kable_styling(bootstrap_options =c("striped", "hover"), full_width = F) %>%row_spec(0, background ="#28a745", color ="white", bold =TRUE) %>%# Green header rowrow_spec(2, background ="#f8f8f5") # Light shading for "Lost" row
KER
Clean
Break
Won
1
0
Lost
0
0
Total
1
0
# Assuming 'Test_again' dataset is already loaded# Count the occurrences of "Turnover Won"turnover_won_count <-sum(Test_again$Turnovers =="Turnover Won", na.rm =TRUE)# Count the occurrences of "Turnover Lost"turnover_lost_count <-sum(Test_again$Turnovers =="Turnover Lost", na.rm =TRUE)# Calculate the total turnoverstotal_turnovers <- turnover_won_count + turnover_lost_count# Print the resultscat("Turnover Won:", turnover_won_count, "\n")
Turnover Won: 3
cat("Turnover Lost:", turnover_lost_count, "\n")
Turnover Lost: 4
cat("Total Turnovers:", total_turnovers, "\n")
Total Turnovers: 7
# Assuming 'Test_again' dataset is already loaded# Count the occurrences for each category in the DEF columndef_won <-sum(Test_again$`Turnover Location`=="TA Defensive Third TO", na.rm =TRUE)def_lost <-sum(Test_again$`Turnover Location`=="TB Defensive Third TO", na.rm =TRUE)def_total <- def_won + def_lost# Count the occurrences for each category in the MID columnmid_won <-sum(Test_again$`Turnover Location`=="TA Middle Third TO", na.rm =TRUE)mid_lost <-sum(Test_again$`Turnover Location`=="TB Middle Third TO", na.rm =TRUE)mid_total <- mid_won + mid_lost# Count the occurrences for each category in the ATT columnatt_won <-sum(Test_again$`Turnover Location`=="TA Attacking Third TO", na.rm =TRUE)att_lost <-sum(Test_again$`Turnover Location`=="TB Attacking Third TO", na.rm =TRUE)att_total <- att_won + att_lost# Create a data frame for the tableturnover_table <-data.frame(Area =c("Won", "Lost", "Total"),DEF =c(def_won, def_lost, def_total),MID =c(mid_won, mid_lost, mid_total),ATT =c(att_won, att_lost, att_total))# Load knitr and kableExtra for creating the tablelibrary(knitr)library(kableExtra)# Render the tablekable(turnover_table, col.names =c("Area", "DEF", "MID", "ATT"), format ="html", align ="c") %>%kable_styling(bootstrap_options =c("striped", "hover"), full_width = F) %>%column_spec(1, color ="black", background ="white") %>%column_spec(2:4, color ="black", background ="white") %>%row_spec(0, background ="#000000", color ="white", bold =TRUE) # Highlight the top row in black
Area
DEF
MID
ATT
Won
1
1
1
Lost
2
1
1
Total
3
2
2
library(ggplot2)# Create a data frame for turnover_long with calculated countsturnover_long <-data.frame(Area =rep(c("Lost", "Won"), each =3), # Repeat "Lost" and "Won" for each AreaTypeAreaType =c("DEF", "MID", "ATT", "DEF", "MID", "ATT"), # Area types (DEF, MID, ATT)Count =c(def_lost, mid_lost, att_lost, def_won, mid_won, att_won) # The counts from above)# Reorder the levels of 'Area' and 'AreaType' to control the ordering in the plotturnover_long$Area <-factor(turnover_long$Area, levels =c("Won", "Lost"))turnover_long$AreaType <-factor(turnover_long$AreaType, levels =c("ATT", "MID", "DEF")) # Swap DEF and ATT# Create the horizontal bar chartggplot(turnover_long, aes(x = Area, y = Count, fill = AreaType)) +geom_bar(stat ="identity", position =position_dodge(width =0.45), width =0.45) +# Side-by-side barsgeom_text(aes(label = Count), position =position_dodge(width =0.45), # Align text with the dodged barscolor ="white", size =5, fontface ="bold",hjust =2) +# Bold text labelsscale_fill_manual(values =c("DEF"="red", "MID"="darkorange", "ATT"="darkgreen")) +# Match colorscoord_flip() +# Flip coordinates for horizontal barstheme_void() +# Remove all background graphicstheme(legend.position ="none", # Remove legendaxis.text.y =element_text(size =10, color ="black", face ="bold"), # Bold Won/Lost labelsaxis.text.x =element_blank(), # Remove X-axis textaxis.ticks =element_blank(), # Remove axis tickspanel.grid =element_blank() # Remove grid lines )