Hockey graphs

The boxplot shows the number of goals allowed by each NHL team. The median of goals allowed are labeled by the line in each box, while the whiskers extend to show the range excluding outliers, which are shown as individual points. Teams with wider boxes have a more inconsistent defense, and those with narrow boxes are more consistent in the number of goals they concede.

ggplot(goalies_data, aes(x = team, y = goals, fill = team))+
  geom_boxplot()+
  coord_flip()+
  scale_fill_brewer(palette ="Paired")+
  labs(title ="Goals Allowed by Team",
       x ="Team", y ="Goals Allowed")+
  theme_minimal()+
  theme(legend.position ="none")

## graph 2 The The The heatmap shows the save percentages of NHL goalies who have played at least 20 games, with each square showing a goalie’s performance for their team. The colors from red to green indicates a range from lower to higher save percentages, providing a quick visual glance of individual goalies’ effectiveness. Teams with goalies in the green range have stronger goaltending, while those with goalies in the red spectrum may face challenges in net. This graph makes sense due to the greener goalies being Vezina award candidates which is the award for the best goalie in the NHL.

goalies_data<-goalies_data%>%
  mutate(save_percentage = ifelse(ongoal >0,(ongoal - goals)/ ongoal, NA)) %>%
  filter(!is.na(save_percentage),games_played >=20)

ggplot(goalies_data, aes(x = reorder(name,save_percentage),y= reorder(team, save_percentage)))+
  geom_tile(aes(fill = save_percentage))+
  scale_fill_gradient2(low = "red",high ="green",mid ="yellow",
                       midpoint= median(goalies_data$save_percentage, na.rm =TRUE), 
                       name = "Save %")+
  labs(title = "Goalie Save Percentage by Team (20 games played)",
       x = "Goalie Name", y = "Team")+
  theme_minimal()+
  theme(axis.text.x = element_text(angle = 45, hjust = 1, vjust = 1))

## graph 19 This This density plot shows the distribution of goals allowed from shots classified as high danger and low danger. The area under each curve shows the ratio of goals allowed from each danger level, with the apex of the red curve showing a higher frequency of goals allowed from high-danger shots. The plot hints that while high-danger shots are less likely, they are more likely to result in goals than low-danger shots, meaning that teams may need to focus on strategies to lower these high-risk chances

goalies_data_long <-pivot_longer(goalies_data, cols = c(highDangerGoals, lowDangerGoals), 
                                  names_to="DangerLevel", values_to = "Goals")

ggplot(goalies_data_long, aes(x = Goals, fill = DangerLevel))+
  geom_density(alpha =0.7)+
  scale_fill_brewer(palette ="Set1") +
  labs(title ="Distribution of Goals Allowed for High vs. Low Danger Shots",
       x = "Goals Allowed",y ="Density") +
  theme_minimal()

## Detroit Graph The bar chart displays the total goals conceided by the Detroit Red Wings in three levels of danger high, medium, and low. The green bar represents the total high danger goals, the orange bar represents the total low danger goals, and the blue bar represents the total medium danger goals. It shows that Detroit has scored the most medium danger goals, followed by a lower number of low danger goals, and the least amount of high danger goals. This is an interesting outlook becuase someone would expect high danger would rank the highest because of the level of likelihood a goal would be scored.

#filter for detroit
det_goalies_data <-goalies_data%>% 
  filter(team =="DET")
#bar graph
ggplot(goals_long,aes(x=DangerLevel,y=Goals,fill=DangerLevel)) +
  geom_bar(stat="identity")+
  coord_flip()+
  theme_minimal()+
  labs(title = "Total Goals by Danger Level for Detroit Red Wings",
       x = "Danger Level",
       y = "Total Goals")+
  scale_fill_brewer(palette = "Set2")#to alter the graphs color

## marque nhl The The graph shows the average save percentage of goalies from top preforming NHL teams in 2024, with each point representing a team’s average and the horizontal lines showing the range of one standard deviation. Teams like Dallas and New York Rangers have goalies with the highest average save percentages, close to a 95% mark, and also display small variability in their performances showing great consistency Teams such as Edmonton and Florida show wider error bars, showing a greater inconsistency in their goalies’ save percentages. This is important to note for playoff teams since these team graphed will mostly likely all be in the playoffs but goaltending is often the difference maker in making a deep run.

#marque nhl teams data
selected_teams <- c("EDM", "BOS", "FLA", "COL", "DAL", "NYR", "VGK", "VAN", "TOR")
#shots on goal are to find save percentage
goalies_data <-goalies_data%>%
  mutate(save_percentage =ifelse(ongoal > 0, (ongoal - goals) / ongoal, NA))

#average save percentage and standard deviation by team
team_save_percentage <- goalies_data%>%
  filter(team %in% selected_teams)%>%
  group_by(team)%>%
  summarise(average_save_percentage = mean(save_percentage,na.rm = TRUE),
            sd_save_percentage =sd(save_percentage,na.rm =TRUE)) %>%
  ungroup() %>%
  arrange(desc(average_save_percentage))
# ranking top nhl teams based on goal tending
ggplot(team_save_percentage, aes(x =reorder(team, -average_save_percentage), y = average_save_percentage)) +
  geom_point(aes(color=team), size=4)+ 
  geom_errorbar(aes(ymin = average_save_percentage - sd_save_percentage, ymax = average_save_percentage + sd_save_percentage, color = team), width = 0.2) + # Add error bars for variability
  coord_flip()+#horizontal plot
  scale_color_brewer(palette = "Set3", guide = FALSE) + 
  labs(title ="Goalie Performance Ranking by Top Teams",
       x ="Team",
       y ="Average Save Percentage",
       caption = "Dots show average save percentage-error bars are 1 std") +
  theme_minimal()+
  theme(axis.text.y =element_text(size =12), 
        plot.title =element_text(hjust =0.5,size =14),
        plot.caption =element_text(hjust =0.5,size =12))