library(readxl)
## Warning: package 'readxl' was built under R version 4.5.1
socdat <- read_excel("soccerdata.xlsx")
hist(socdat$Points,
breaks = 6,
col = "lightblue",
border = "white",
main = "Distribution of Points",
xlab = "Points",
ylab = "Frequency")

library(shiny)
## Warning: package 'shiny' was built under R version 4.5.3
library(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.5.2
ui <- fluidPage(
titlePanel("Interactive Scatter Plot with Regression Line"),
sidebarLayout(
sidebarPanel(
selectInput(
"xvar",
"Choose X Variable:",
choices = c("Goal Difference", "Last 8 Matches PPG", "Clean Sheets")
)
),
mainPanel(
plotOutput("scatterPlot")
)
)
)
server <- function(input, output) {
output$scatterPlot <- renderPlot({
ggplot(socdat, aes(x = .data[[input$xvar]], y = .data[["Points"]])) +
geom_point() +
geom_smooth(method = "lm", se = TRUE) +
labs(
title = paste(input$xvar, "vs Points"),
x = input$xvar,
y = "Points"
) +
theme_minimal()
})
}
shinyApp(ui = ui, server = server)
Shiny applications not supported in static R Markdown documents
socdat$`Table Group` <- factor(
socdat$`Table Group`,
levels = c("Relegated", "Relegation Battle", "Mid-table",
"European Contenders", "Top 4")
)
ui <- fluidPage(
titlePanel("Interactive Plot by Table Group"),
sidebarLayout(
sidebarPanel(
selectInput(
"yvar",
"Choose Numeric Variable:",
choices = c("Goal Difference", "Last 8 Matches PPG", "Clean Sheets")
)
),
mainPanel(
plotOutput("groupPlot")
)
)
)
server <- function(input, output) {
output$groupPlot <- renderPlot({
ggplot(socdat, aes(x = .data[["Table Group"]], y = .data[[input$yvar]])) +
geom_boxplot() +
geom_jitter(width = 0.15, alpha = 0.7) +
labs(
title = paste(input$yvar, "by Table Group"),
x = "Table Group",
y = input$yvar
) +
theme_minimal()
})
}
shinyApp(ui = ui, server = server)
Shiny applications not supported in static R Markdown documents
hist(socdat$`Goal Difference`,
breaks = 10,
col = "lightblue",
border = "white",
main = "Distribution of Goal Difference",
xlab = "Goal Difference",
ylab = "Frequency")

socdat$`Table Group` <- factor(
socdat$`Table Group`,
levels = c("Relegated", "Relegation Battle", "Mid-table",
"European Contenders", "Top 4")
)
years <- sort(unique(socdat$Year))
ui <- fluidPage(
titlePanel("Goal Difference Scatterplot by Season"),
sidebarLayout(
sidebarPanel(
sliderInput(
"year",
"Select Year:",
min = 1,
max = length(years),
value = 1,
step = 1,
ticks = FALSE,
animate = TRUE
),
textOutput("year_label")
),
mainPanel(
plotOutput("scatterPlot")
)
)
)
server <- function(input, output) {
selected_year <- reactive({
years[input$year]
})
output$year_label <- renderText({
paste("Season:", selected_year())
})
output$scatterPlot <- renderPlot({
season_data <- subset(socdat, Year == selected_year())
ggplot(season_data, aes(x = `Goal Difference`, y = Points, color = `Table Group`)) +
geom_point(size = 3, alpha = 0.8) +
labs(
title = paste("Goal Difference vs Points in", selected_year()),
x = "Goal Difference",
y = "Points",
color = "Table Group"
) +
theme_minimal() +
ylim(min(socdat$Points, na.rm = TRUE), max(socdat$Points, na.rm = TRUE))
})
}
shinyApp(ui = ui, server = server)
Shiny applications not supported in static R Markdown documents
socdat$`Table Group` <- factor(
socdat$`Table Group`,
levels = c("Relegated", "Relegation Battle", "Mid-table",
"European Contenders", "Top 4")
)
years <- sort(unique(socdat$Year))
ui <- fluidPage(
titlePanel("Clean Sheets Scatterplot by Season"),
sidebarLayout(
sidebarPanel(
sliderInput(
"year",
"Select Year:",
min = 1,
max = length(years),
value = 1,
step = 1,
ticks = FALSE,
animate = TRUE
),
textOutput("year_label")
),
mainPanel(
plotOutput("scatterPlot")
)
)
)
server <- function(input, output) {
selected_year <- reactive({
years[input$year]
})
output$year_label <- renderText({
paste("Season:", selected_year())
})
output$scatterPlot <- renderPlot({
season_data <- subset(socdat, Year == selected_year())
ggplot(season_data, aes(x = `Clean Sheets`, y = Points, color = `Table Group`)) +
geom_point(size = 3, alpha = 0.8) +
labs(
title = paste("Clean Sheets vs Points in", selected_year()),
x = "Clean Sheets",
y = "Points",
color = "Table Group"
) +
theme_minimal() +
ylim(min(socdat$Points, na.rm = TRUE), max(socdat$Points, na.rm = TRUE))
})
}
shinyApp(ui = ui, server = server)
Shiny applications not supported in static R Markdown documents