Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
89 lines (73 sloc) 3.62 KB
---
title: "JapanDepthFrontend"
output: html_document
---
```{r}
df <- read.csv("minutes.csv")[,-c(1)]
str(df)
#Grouped positions:
#2nd/3rd Row
SecondThirdRow.df <- df[df$Position == "SBR",] #subset for the position
SecondThirdRow.df.sorted <- SecondThirdRow.df[order(-SecondThirdRow.df$Minutes),] #descending order of minutes played
SecondThirdRow.df.sorted$Name
#Fly Half/Centre
FlyHalfCentre.df <- df[df$Position == "FHC",] #subset for the position
FlyHalfCentre.df.sorted <- FlyHalfCentre.df[order(-FlyHalfCentre.df$Minutes),] #descending order of minutes played
FlyHalfCentre.df.sorted$Name
#Back Three
BackThree.df <- df[df$Position == "BT",] #subset for the position
BackThree.df.sorted <- BackThree.df[order(-BackThree.df$Minutes),] #descending order of minutes played
BackThree.df.sorted$Name
#Individual positions:
#Loosehead
Loosehead.df <- df[df$Position == "LP",] #subset for the position
Loosehead.df.sorted <- Loosehead.df[order(-Loosehead.df$Minutes),] #descending order of minutes played
Loosehead.df.sorted$Name
#Hooker
Hooker.df <- df[df$Position == "H",] #subset for the position
Hooker.df.sorted <- Hooker.df[order(-Hooker.df$Minutes),] #descending order of minutes played
Hooker.df.sorted$Name
#Tighthead
Tighthead.df <- df[df$Position == "TP",] #subset for the position
Tighthead.df.sorted <- Tighthead.df[order(-Tighthead.df$Minutes),] #descending order of minutes played
Tighthead.df.sorted$Name
#Scrum Half
ScrumHalf.df <- df[df$Position == "SH",] #subset for the position
ScrumHalf.df.sorted <- ScrumHalf.df[order(-ScrumHalf.df$Minutes),] #descending order of minutes played
ScrumHalf.df.sorted$Name
position.names <- c("1", "2", "3", "4 - 8", "9", "FH&C", "W&FB")
```
Mimic the stacked bar chart:
https://plot.ly/r/bar-charts/
```{r}
#Make three stacked bar charts
library(plotly)
```
```{r}
#Merge the minutes into one matrix
minutes.matrix <- cbind(c(Loosehead.df.sorted$Minutes/sum(Loosehead.df.sorted$Minutes))[1:3],
c(Hooker.df.sorted$Minutes/sum(Hooker.df.sorted$Minutes))[1:3],
c(Tighthead.df.sorted$Minutes/sum(Tighthead.df.sorted$Minutes))[1:3],
c(sum(SecondThirdRow.df.sorted$Minutes[1:4]/sum(SecondThirdRow.df.sorted$Minutes)),
sum(SecondThirdRow.df.sorted$Minutes[5:8]/sum(SecondThirdRow.df.sorted$Minutes)),
sum(SecondThirdRow.df.sorted$Minutes[9:12]/sum(SecondThirdRow.df.sorted$Minutes))
),
c(ScrumHalf.df.sorted$Minutes/sum(ScrumHalf.df.sorted$Minutes))[1:3],
c(sum(FlyHalfCentre.df.sorted$Minutes[1:2]/sum(FlyHalfCentre.df.sorted$Minutes)),
sum(FlyHalfCentre.df.sorted$Minutes[3:4]/sum(FlyHalfCentre.df.sorted$Minutes)),
sum(FlyHalfCentre.df.sorted$Minutes[5:6]/sum(FlyHalfCentre.df.sorted$Minutes))
),
c(sum(BackThree.df.sorted$Minutes[1:2]/sum(BackThree.df.sorted$Minutes)),
sum(BackThree.df.sorted$Minutes[3:4]/sum(BackThree.df.sorted$Minutes)),
sum(BackThree.df.sorted$Minutes[5:6]/sum(BackThree.df.sorted$Minutes))
)
)
#start of with first choice players:
p <- plot_ly(df, x = as.factor(position.names), y = ~minutes.matrix[3,], type = 'bar', name = "Third Choice") %>%
#second and third choice players:
add_trace(y = ~minutes.matrix[2,], name = "Second Choice") %>%
add_trace(y = ~minutes.matrix[1,], name = "First Choice") %>%
#finish off:
layout(yaxis = list(title = 'Game minutes proportion'), barmode = 'stack')
p
```