-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2024-10-27 preseason number 1 teams.R
68 lines (57 loc) · 3.48 KB
/
2024-10-27 preseason number 1 teams.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
#generated by perplexity.ai
library(ggplot2)
library(dplyr)
teams_data <- data.frame(
season = c("2023-24", "2022-23", "2021-22", "2020-21", "2019-20", "2018-19", "2017-18", "2016-17", "2015-16", "2014-15", "2013-14", "2012-13", "2011-12", "2010-11", "2009-10", "2008-09", "2007-08", "2006-07", "2005-06", "2004-05", "2003-04", "2002-03", "2001-02", "2000-01", "1999-00", "1998-99", "1997-98", "1996-97", "1995-96", "1994-95", "1993-94", "1992-93", "1991-92", "1990-91", "1989-90", "1989-90", "1988-89", "1987-88", "1986-87", "1985-86", "1984-85", "1983-84", "1982-83", "1981-82"),
team = c("LSU", "South Carolina", "South Carolina", "South Carolina", "Oregon", "Notre Dame", "UConn", "Notre Dame", "UConn", "UConn", "UConn", "Baylor", "Baylor", "UConn", "UConn", "UConn", "Tennessee", "Maryland", "Duke", "Tennessee", "UConn", "Duke", "UConn", "UConn", "UConn", "Tennessee", "Tennessee", "Stanford", "UConn", "Tennessee", "Tennessee", "Stanford", "Tennessee", "Virginia", "Tennessee", "Louisiana Tech", "Tennessee", "Tennessee", "Texas", "Texas", "Georgia", "USC", "USC", "Louisiana Tech"),
wins = c(31, 36, 35, 26, 31, 35, 36, 33, 38, 38, 40, 34, 40, 36, 39, 39, 36, 28, 31, 30, 31, 35, 39, 32, 36, 31, 39, 34, 34, 34, 31, 26, 28, 31, 27, 32, 35, 31, 31, 34, 29, 29, 30, 35),
losses = c(6, 1, 2, 5, 2, 4, 1, 4, 0, 1, 0, 2, 0, 2, 0, 0, 2, 6, 4, 5, 4, 2, 0, 3, 1, 3, 0, 2, 4, 3, 2, 6, 3, 3, 6, 1, 2, 3, 2, 0, 5, 4, 2, 1)
)
# Calculate win percentage
teams_data <- teams_data %>%
mutate(win_percentage = wins / (wins + losses))
# Create the plot
ggplot(teams_data, aes(x = reorder(paste(team, season), win_percentage), y = win_percentage, fill = team)) +
geom_bar(stat = "identity") +
coord_flip() +
scale_y_continuous(labels = scales::percent_format(), limits = c(0, 1)) +
labs(title = "Women's Basketball Preseason No. 1 Teams Records (1981-82 to 2023-24)",
x = "",
y = "Win Percentage",
fill = "Team") +
theme_minimal() +
theme(legend.position = "none",
axis.text.y = element_text(size = 6)) +
geom_text(aes(label = paste(wins, "-", losses)), hjust = -0.1, size = 2.5)
ggplot(teams_data) +
geom_bar(aes(x = reorder(paste(team, season), win_percentage), y = win_percentage, fill = win_percentage), stat = 'identity') +
coord_flip() +
scale_fill_gradient(low = 'red', high = 'yellow') +
scale_y_continuous(
labels = scales::percent_format(accuracy = 1),
limits = c(0, 1.1),
breaks = seq(0, 1, 0.25), # This will create breaks at 0%, 25%, 50%, 75%, and 100%
expand = c(0, 0) # This removes the space between the axis and the bars
) +
labs(title = 'Women\'s Basketball Preseason No.1 Teams',
subtitle = 'Win Percentages (1981–82 to 2023–24)',
x = '',
y = 'Win %',
fill = 'Win %') +
theme_minimal() +
theme(
plot.title = element_text(size = 12, face = "bold"),
plot.subtitle = element_text(size = 10),
axis.text.y = element_text(size = 6),
axis.text.x = element_text(size = 8),
legend.position = "none",
plot.margin = margin(5, 20, 5, 5), # Increase right margin
aspect.ratio = 2.5
) +
geom_text(aes(x = reorder(paste(team, season), win_percentage),
y = win_percentage,
label = paste(wins, "-", losses)),
hjust = 1, # Align text to the right edge of the bar
nudge_y = 0.02, # Move text slightly above the bar
size = 2,
color = "black")