Improved charts with ggplot2
This commit is contained in:
parent
83b050d711
commit
3b077f5269
226
.Rhistory
226
.Rhistory
@ -277,3 +277,229 @@ runApp()
|
|||||||
runApp()
|
runApp()
|
||||||
runApp()
|
runApp()
|
||||||
runApp()
|
runApp()
|
||||||
|
shiny::runApp()
|
||||||
|
install.packages("shinythemes")
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
View(test)
|
||||||
|
View(balance)
|
||||||
|
View(bal)
|
||||||
|
balancePercTest <- bal %>% mutate(percentage = n/sum(.$n))
|
||||||
|
head(balancePercTest)
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
balPerc <- getBalancePercentage(
|
||||||
|
getBalance(getMatchesList(input$first_team, input$second_team, football_data_ext))
|
||||||
|
)
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
View(football_data)
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
View(football_data)
|
||||||
|
getMatchesList("England", "Scotland", football_data)
|
||||||
|
getMatchesList("England", "Scotland", football_data) %>% arrange()
|
||||||
|
getMatchesList("England", "Scotland", football_data) %>% arrange(decreasing=TRUE)
|
||||||
|
getMatchesList("England", "Scotland", football_data) %>% arrange(.,decreasing=TRUE)
|
||||||
|
getMatchesList("England", "Scotland", football_data) %>% arrange(.$date)
|
||||||
|
getMatchesList("England", "Scotland", football_data) %>% arrange(.$date, decreasing=TRUE)
|
||||||
|
getMatchesList("England", "Scotland", football_data) %>% mutate(date = as.Date(date, "%Y-%m-%d")) %>% sort(date)
|
||||||
|
getMatchesList("England", "Scotland", football_data) %>% mutate(date = as.Date(date, "%Y-%m-%d")) %>% sort(date, decreasing = TRUE)
|
||||||
|
football_data %>% select(date)
|
||||||
|
football_data %>% select(date) %>% min()
|
||||||
|
football_data %>% select(date) %>% format(date, "%Y")
|
||||||
|
football_data %>% select(date) %>% format(.$date, "%Y")
|
||||||
|
football_data %>% select(date) %>% typeof()
|
||||||
|
football_data %>% select(date) %>% format(as.Date(date, format="%Y-%m-%d"),"%Y")
|
||||||
|
test <- football_data %>% select(date)
|
||||||
|
test[1]
|
||||||
|
test %>% head(1)
|
||||||
|
test %>% head(1) %>% format(., "%Y")
|
||||||
|
test %>% head(1) %>% typeof
|
||||||
|
test %>% head(1) %>% typeof()
|
||||||
|
football_data %>% select(date) %>% min()
|
||||||
|
football_data %>% select(date)
|
||||||
|
football_data %>% select(date) %>% aggregate(., by=list(.), max)
|
||||||
|
football_data %>% min(.$date)
|
||||||
|
football_data %>% select(date) %>% summarise(min = min(date))
|
||||||
|
football_data %>% select(date) %>% mutate(date = as.Date(date, "%Y-%m-%d")) %>% summarise(min = min(date))
|
||||||
|
football_data %>% select(date) %>% mutate(. = as.Date(date, "%Y-%m-%d")) %>% summarise(min = min(.))
|
||||||
|
football_data %>% select(date) %>% mutate(. = as.Date(., "%Y-%m-%d")) %>% summarise(min = min(.))
|
||||||
|
getDateFromData <- function(matchesData) {
|
||||||
|
return(
|
||||||
|
matchesData %>%
|
||||||
|
select(date) %>%
|
||||||
|
mutate(date = as.Date(date, "%Y-%m-%d"))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
getDateFromData(football_data) %>%
|
||||||
|
summarise(max = max(date))
|
||||||
|
balance <- football_data %>%
|
||||||
|
count(winner, sort = TRUE)
|
||||||
|
return(balance)
|
||||||
|
runApp()
|
||||||
|
getDateFromData(football_data)
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
typeof(min_date_from)
|
||||||
|
getDateFromData(football_data) %>%
|
||||||
|
summarise(min = min(date)) %>% as.Date()
|
||||||
|
getDateFromData(football_data) %>%
|
||||||
|
summarise(min = min(date)) %>% as.Date(., format = "%Y-%m-%d")
|
||||||
|
getDateFromData(football_data) %>%
|
||||||
|
summarise(min = min(date)) %>% as.Date(date, format = "%Y-%m-%d")
|
||||||
|
getDateFromData(football_data) %>%
|
||||||
|
summarise(min = min(date)) %>% as.Date(date)
|
||||||
|
getDateFromData(football_data) %>%
|
||||||
|
summarise(min = min(date)) %>% strptime(date, "%Y-%m-%d")
|
||||||
|
getDateFromData(football_data) %>%
|
||||||
|
summarise(min = min(date)) %>% strptime(., "%Y-%m-%d")
|
||||||
|
getDateFromData(football_data) %>%
|
||||||
|
summarise(min = min(date))
|
||||||
|
getDateFromData(football_data) %>%
|
||||||
|
summarise(min = min(date)) %>% top_n(1)
|
||||||
|
getDateFromData(football_data) %>%
|
||||||
|
summarise(min = min(date)) %>% top_n(1) %>% typeof
|
||||||
|
runApp()
|
||||||
|
getDateFromData(football_data) %>%
|
||||||
|
summarise(min = min(date)) %>% slice(1)
|
||||||
|
getDateFromData(football_data) %>%
|
||||||
|
summarise(min = min(date)) %>% pull()
|
||||||
|
runApp()
|
||||||
|
getDateFromData(football_data) %>%
|
||||||
|
summarise(min = min(date)) %>% pull() %>% typeof()
|
||||||
|
getDateFromData(football_data) %>%
|
||||||
|
summarise(min = min(date)) %>% pull() %>% as.Date(., format = "%Y-%m-%d")
|
||||||
|
getDateFromData(football_data) %>%
|
||||||
|
summarise(min = min(date)) %>% pull() %>% as.Date(., format = "%Y-%m-%d") %>% typeof()
|
||||||
|
test <- getDateFromData(football_data) %>%
|
||||||
|
summarise(min = min(date)) %>% pull()
|
||||||
|
as.Date(test, "%Y-%m-%d")
|
||||||
|
as.Date(test, "%Y-%m-%d") %>% typeof()
|
||||||
|
test <- as.Date(test, "%Y-%m-%d")
|
||||||
|
typeof(test)
|
||||||
|
as.character(test)
|
||||||
|
test <- as.character(test)
|
||||||
|
test
|
||||||
|
typeof(test)
|
||||||
|
test <- as.Date(test, "%Y-%m-%d")
|
||||||
|
test
|
||||||
|
typeof(test)
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
test_date <- as.Date("2000-01-01", "%Y-%m-%d")
|
||||||
|
football_data %>% filter(as.Date(as.character(date, "%Y-%d-%m")) >= test_date)
|
||||||
|
runApp()
|
||||||
|
football_data %>%
|
||||||
|
filter(as.Date(as.character(date, "%Y-%d-%m")) >= as.Date(as.character(test_date, "%Y-%d-%m"))
|
||||||
|
& as.Date(as.character(date, "%Y-%d-%m")) <= as.Date(as.character(max_date_to, "%Y-%d-%m")))
|
||||||
|
football_data %>%
|
||||||
|
filter(as.Date(as.character(date, "%Y-%d-%m")) >= as.Date(as.character(test_date, "%Y-%d-%m")))
|
||||||
|
runApp()
|
||||||
|
install.packages("lubridate")
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
dateFrom <- as.Date(as.character(dateFrom, "%Y-%m-%d"))
|
||||||
|
runApp()
|
||||||
|
as_date(test)
|
||||||
|
test_date <- as_date(test)
|
||||||
|
test_date
|
||||||
|
typeof(test_date)
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
football_data %>% filter(as_date(date) >= test_date)
|
||||||
|
runApp()
|
||||||
|
getMatchesList <- function(matchesData, first_team, second_team) {
|
||||||
|
return(
|
||||||
|
matchesData %>%
|
||||||
|
filter(home_team %in% c(first_team, second_team)
|
||||||
|
& away_team %in% c(first_team, second_team)) %>%
|
||||||
|
arrange()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
getMatchesList(football_data, "England", "Scotland")
|
||||||
|
getMatchesList(football_data, "England", "Scotland") %>% filterByDate(min_date_from, max_date_to)
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
View(football_data_ext)
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
install.packages("shinydashboard")
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
runApp()
|
||||||
|
@ -28,5 +28,5 @@ getBalance <- function(football_data) {
|
|||||||
|
|
||||||
getBalancePercentage <- function(balance) {
|
getBalancePercentage <- function(balance) {
|
||||||
balancePerc <- balance %>%
|
balancePerc <- balance %>%
|
||||||
mutate(percentage = n/sum(.$n) * 100)
|
mutate(percentage = n/sum(.$n))
|
||||||
}
|
}
|
@ -27,27 +27,23 @@ getBalanceData <- function(input) {
|
|||||||
|
|
||||||
balanceBetweenTeams <- function(input, output) {
|
balanceBetweenTeams <- function(input, output) {
|
||||||
output$balance <- renderPlot({
|
output$balance <- renderPlot({
|
||||||
barplot(
|
ggplot(getFilteredResults(input), aes(x=as.factor(winner),
|
||||||
getBalanceData(input)$n,
|
fill=as.factor(n))) +
|
||||||
main = "Balance between teams",
|
geom_bar(fill = rgb(0.1,0.4,0.5,0.7)) +
|
||||||
col = rainbow(3),
|
theme_minimal() +
|
||||||
names.arg = getBalanceData(input)$winner
|
labs(x = "", y = "Number of matches")
|
||||||
)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
# Balance percentage
|
# Balance percentage
|
||||||
balancePercentage <- function(input, output) {
|
balancePercentage <- function(input, output) {
|
||||||
output$balancePieChart <- renderPlot({
|
output$balancePieChart <- renderPlot({
|
||||||
pie(
|
ggplot(getBalancePercentage(getBalanceData(input))) +
|
||||||
getBalancePercentage(
|
geom_bar(
|
||||||
getBalanceData(input)
|
aes(x="", y=percentage, fill=winner),
|
||||||
)$percentage,
|
stat = "identity") +
|
||||||
main = "Match balance (percentage)",
|
coord_polar("y", start = 0) +
|
||||||
labels = getBalancePercentage(
|
theme_void() +
|
||||||
getBalanceData(input)
|
geom_text(aes(x=1, y = cumsum(percentage) - percentage/2, label = percent(percentage)))
|
||||||
)$winner,
|
|
||||||
col = rainbow(3)
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
}
|
}
|
17
UI/BalanceComponent.R
Normal file
17
UI/BalanceComponent.R
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
# Balance component
|
||||||
|
|
||||||
|
balanceComponent <- function(pieChartSize, barplotSize)
|
||||||
|
{
|
||||||
|
fluidRow(
|
||||||
|
column(barplotSize,
|
||||||
|
wellPanel(
|
||||||
|
plotOutput("balance")
|
||||||
|
)
|
||||||
|
),
|
||||||
|
column(pieChartSize,
|
||||||
|
wellPanel(
|
||||||
|
plotOutput("balancePieChart")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
30
UI/UI.R
Normal file
30
UI/UI.R
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#
|
||||||
|
# Main UI File
|
||||||
|
#
|
||||||
|
|
||||||
|
# Import files
|
||||||
|
source("UI/SidebarPanel.R")
|
||||||
|
source("UI/BalanceComponent.R")
|
||||||
|
|
||||||
|
# UI
|
||||||
|
ui <- fluidPage(
|
||||||
|
theme = shinytheme("cerulean"),
|
||||||
|
|
||||||
|
# Application title
|
||||||
|
headerPanel("International football results 1872-2018"),
|
||||||
|
|
||||||
|
# Sidebar layout elements
|
||||||
|
sidebarLayout(
|
||||||
|
teamsSidebarPanel(),
|
||||||
|
|
||||||
|
# Main panel
|
||||||
|
mainPanel(
|
||||||
|
fluidPage(
|
||||||
|
balanceComponent(6, 6),
|
||||||
|
fluidRow(
|
||||||
|
DT::dataTableOutput("results_pagination")
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
26
UI/main.R
26
UI/main.R
@ -1,26 +0,0 @@
|
|||||||
#
|
|
||||||
# Main UI File
|
|
||||||
#
|
|
||||||
|
|
||||||
# Import files
|
|
||||||
source("UI/SidebarPanel.R")
|
|
||||||
|
|
||||||
# UI
|
|
||||||
ui <- fluidPage(
|
|
||||||
theme = shinytheme("slate"),
|
|
||||||
|
|
||||||
# Application title
|
|
||||||
titlePanel("International football results 1872-2018"),
|
|
||||||
|
|
||||||
# Sidebar layout elements
|
|
||||||
sidebarLayout(
|
|
||||||
teamsSidebarPanel(),
|
|
||||||
|
|
||||||
# Main panel
|
|
||||||
mainPanel(
|
|
||||||
plotOutput("balance"),
|
|
||||||
plotOutput("balancePieChart"),
|
|
||||||
DT::dataTableOutput("results_pagination")
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
6
app.R
6
app.R
@ -11,11 +11,13 @@ library(shiny)
|
|||||||
library(dplyr)
|
library(dplyr)
|
||||||
library(shinythemes)
|
library(shinythemes)
|
||||||
library(lubridate)
|
library(lubridate)
|
||||||
|
library(ggplot2)
|
||||||
|
library(scales)
|
||||||
|
|
||||||
# Load files
|
# Load files
|
||||||
source("Data/Loader.R")
|
source("Data/Loader.R")
|
||||||
source("UI/main.R")
|
source("UI/UI.R")
|
||||||
source("Server/main.R")
|
source("Server/Server.R")
|
||||||
|
|
||||||
# Run the application
|
# Run the application
|
||||||
shinyApp(ui = ui, server = server)
|
shinyApp(ui = ui, server = server)
|
||||||
|
Loading…
Reference in New Issue
Block a user