Added balance for one team
This commit is contained in:
parent
278bd6ca8c
commit
553164e6bf
@ -36,4 +36,16 @@ getBalance <- function(football_data) {
|
||||
getBalancePercentage <- function(balance) {
|
||||
balancePerc <- balance %>%
|
||||
mutate(percentage = n/sum(.$n))
|
||||
}
|
||||
|
||||
getBalanceForTeam <- function(football_data, team) {
|
||||
balance_full <- football_data %>%
|
||||
count(winner, sort = TRUE)
|
||||
balance <- balance_full[(balance_full$winner %in% c(team, "Draw")),]
|
||||
other_sum <- sum(balance_full[!(balance_full$winner %in% c(team, "Draw")),]$n)
|
||||
balance <- balance %>%
|
||||
rbind(c("Other", other_sum))
|
||||
balance <- balance %>%
|
||||
mutate(n = as.numeric(as.character(n)))
|
||||
return(balance)
|
||||
}
|
@ -5,7 +5,7 @@
|
||||
# Results with pagination
|
||||
getFilteredResultsForTeam <- function(input) {
|
||||
getMatchesForTeam(football_data, input$team) %>%
|
||||
filterByDate(as_date(input$date_range[1]), as_date(input$date_range[2]))
|
||||
filterByDate(as_date(input$date_range_for_team[1]), as_date(input$date_range_for_team[2]))
|
||||
}
|
||||
|
||||
getFilteredResults <- function(input) {
|
||||
@ -38,10 +38,6 @@ matchesForTeam <- function(input, output) {
|
||||
}
|
||||
|
||||
# Balance
|
||||
getBalanceData <- function(input) {
|
||||
getBalance(getFilteredResults(input))
|
||||
}
|
||||
|
||||
balanceBetweenTeams <- function(input, output) {
|
||||
output$balance <- renderPlot({
|
||||
ggplot(getFilteredResults(input), aes(x=as.factor(winner),
|
||||
@ -52,7 +48,27 @@ balanceBetweenTeams <- function(input, output) {
|
||||
})
|
||||
}
|
||||
|
||||
getBalanceDataForTeamBarplot <- function(input) {
|
||||
return(
|
||||
getBalanceForTeam(getFilteredResultsForTeam(input), input$team)
|
||||
)
|
||||
}
|
||||
|
||||
balanceForTeamBarplot <- function(input, output) {
|
||||
output$balance_for_team <- renderPlot({
|
||||
ggplot(getBalanceDataForTeamBarplot(input),
|
||||
aes(x=as.factor(winner), y=as.factor(n))) +
|
||||
geom_bar(stat = "identity", fill = rgb(0.6, 0.1, 0.4, 0.7)) +
|
||||
theme_minimal() +
|
||||
labs(x = "", y = "Matches balance for")
|
||||
})
|
||||
}
|
||||
|
||||
# Balance percentage
|
||||
getBalanceData <- function(input) {
|
||||
getBalance(getFilteredResults(input))
|
||||
}
|
||||
|
||||
balancePercentage <- function(input, output) {
|
||||
output$balancePieChart <- renderPlot({
|
||||
ggplot(getBalancePercentage(getBalanceData(input))) +
|
||||
@ -65,6 +81,4 @@ balancePercentage <- function(input, output) {
|
||||
y = cumsum(percentage) - percentage/2,
|
||||
label = percent(percentage)))
|
||||
})
|
||||
}
|
||||
|
||||
# Top teams barplot
|
||||
}
|
@ -9,6 +9,7 @@ source("Server/DataProcessor.R")
|
||||
# Server logic
|
||||
server <- function(input, output) {
|
||||
# Tab 1
|
||||
balanceForTeamBarplot(input, output)
|
||||
matchesForTeam(input, output)
|
||||
|
||||
# Tab 2
|
||||
|
@ -47,7 +47,7 @@ teamSidebarPanel <- function() {
|
||||
selectInput("team",
|
||||
"Choose team:",
|
||||
teams),
|
||||
dateRangeInput("date_range",
|
||||
dateRangeInput("date_range_for_team",
|
||||
"Date range:",
|
||||
start = min_date_from,
|
||||
end = max_date_to,
|
||||
|
Loading…
Reference in New Issue
Block a user