-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbeerleaguestats.R
113 lines (89 loc) · 3.18 KB
/
beerleaguestats.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
library(readxl)
library(lubridate)
library(ggplot2)
library(crosstable)
library(tidyverse)
library(dplyr)
library(shinydashboard)
library(shiny)
# start dashboard
dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody()
)
# view dashboard
ui <- dashboardPage(
dashboardHeader(),
dashboardSidebar(),
dashboardBody()
)
server <- function(input, output) { }
shinyApp(ui, server)
stats <- read_xlsx("HockeyStats.xlsx", sheet = 2)
str(stats)
attach(stats)
stats <- as.data.frame(stats)
names(stats)
names(stats) [1:15] <- c("date", "yr", "league", "season", "session", "team", "vs",
"gf", "ga", "result", "pos", "goals", "assists", "points", "pim")
squidcolors <- c("#001628", "#99D9D9", "#68A2B9", "#E9072B")
stats <- stats %>%
mutate(result = factor(result, levels = c("W", "L", "T")))
str(stats)
stats <- stats %>%
mutate(month = month(date, label = TRUE))
# skahl
skahl <- subset(stats, league == "SKAHL D")
str(skahl)
# squids
squids <- subset(stats, team == "Squid Squad")
head(squids)
ggplot(skahl, aes(x=date, y=points, color=result)) +
geom_point()
crosstable(skahl, c(gf,ga, result), by=team) %>%
as_flextable()
squids <- subset(stats, team == "Squid Squad")
head(squids)
ggplot(squids, aes(x=result, fill=result)) +
geom_bar() +
scale_fill_manual(values = c("#99D9D9", "#E9072B","#68A2B9")) +
facet_wrap(~ session)
ggplot(squids, aes(x = gf, y = ga, shape = season, color = result)) +
geom_point() +
geom_smooth(method = "lm", se = FALSE) + # Add regression line
scale_color_manual(values = c("#99D9D9", "#E9072B", "#68A2B9")) +
labs(title = "Squid Squad Goals For vs. Goals Against", x = "Goals For", y = "Goals Against") +
theme_minimal()
ggplot(squids, aes(x=goals, y=assists, shape=season, color=result)) +
geom_point() +
scale_color_manual(values = c("#99D9D9", "#E9072B", "#68A2B9"))
# Create the histogram with a smaller binwidth
ggplot(squids, aes(x = points)) +
geom_histogram(binwidth = 1) + # Smaller binwidth for closer bins
labs(title = "Distribution of Points", x = "Points", y = "Count") +
theme_minimal()
ggplot(stats, aes(x=month)) +
geom_histogram(stat = "count", fill = "#99D9D9", color = "black") +
labs(title = "Games Played by Month", x = "Month", y = "Count") +
theme_minimal()
ggplot(skahl, aes(x=team)) +
geom_histogram(stat = "count", fill = "#99D9D9", color = "black") +
labs(title = "Games Played by Team", x = "Team", y = "games") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
ggplot(skahl, aes(x=pos)) +
geom_histogram(stat= "count", fill = "#99D9D9", color = "black") +
labs(title = "Games Played by Position", x = "Position", y = "games") +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
squids_sorted <- squids %>%
mutate(vs = factor(vs, levels = unique(vs))) %>%
group_by(vs) %>%
summarise(total_points = sum(points)) %>%
arrange(desc(total_points))
ggplot(squids_sorted, aes(x = vs, y = total_points)) +
geom_bar(stat = "identity", fill = "#99D9D9", color = "black") +
labs(title = "Points by Opponent", x = "Opponent", y = "Points") +
theme_bw() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))