At first I downloaded the tidy tuesday data from the github and then selected two CSV files containing data for analysis. The first file, Team Results.csv, likely has information about team performance, such as match outcomes and scores. The second file, Public Picks.csv, probably contains data on public predictions or picks, such as which teams people believe will win matches or tournaments. I used the read_csv() function from the readr package to load these files into R as data frames named team_results and public_picks, respectively. Then, I displayed the first few rows of each dataset using the head() function to get a sense of the data’s structure and content.

# Display column names of the merged dataset
colnames(merged_data)
##  [1] "TEAM"      "TEAM ID"   "PAKE"      "PAKE RANK" "PASE"      "PASE RANK"
##  [7] "GAMES"     "W"         "L"         "WIN%"      "R64.x"     "R32.x"    
## [13] "S16.x"     "E8.x"      "F4.x"      "F2"        "CHAMP"     "TOP2"     
## [19] "F4%"       "CHAMP%"    "YEAR"      "TEAM NO"   "R64.y"     "R32.y"    
## [25] "S16.y"     "E8.y"      "F4.y"      "FINALS"
# Correct the percentage_columns vector based on actual column names with suffixes
percentage_columns <- c("R64.y", "R32.y", "S16.y", "E8.y", "F4.y", "FINALS")

# Convert the percentage strings to numeric values
merged_data[percentage_columns] <- lapply(merged_data[percentage_columns], function(x) as.numeric(sub("%", "", x)) / 100)

# Quick verification
head(merged_data[percentage_columns])
##    R64.y  R32.y  S16.y   E8.y   F4.y FINALS
## 1 0.0716 0.0218 0.0063 0.0022 0.0010 0.0004
## 2 0.8711 0.5573 0.1355 0.0731 0.0289 0.0110
## 3 0.9519 0.8105 0.5202 0.2226 0.1005 0.0406
## 4 0.9017 0.5997 0.1593 0.0795 0.0364 0.0134
## 5 0.9234 0.7107 0.3368 0.1215 0.0435 0.0183
## 6 0.7517 0.2170 0.0692 0.0164 0.0064 0.0032

Graph Top 10 Teams with the Most Wins:

Code Description: Utilizing the group_by(), summarize(), and arrange() functions from the dplyr package, this code calculates the total number of wins for each team and selects the top 10 teams with the highest total wins. The resulting data is then visualized using ggplot2 to create a horizontal bar plot. Insight: Identifies and visually represents the top-performing teams based on the total number of wins.

Graph Relationship Between Games Played and Win Percentage:

Code Description: This code section employs ggplot2 to create a scatter plot to explore the relationship between the total number of games played (GAMES) and the win percentage (WIN%) for each team. It includes a trend line using geom_smooth() to illustrate any potential linear relationship. Insight: Allows for the examination of how win percentage correlates with the number of games played.

## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union

## `geom_smooth()` using formula = 'y ~ x'

Graph Top Performers by Win Percentage:

Code Description: Using arrange() and slice_head() functions from dplyr, this code selects the top 10 teams with the highest win percentages and creates a vertical bar plot using ggplot2. Insight: Provides a clear comparison of win percentages among the top-performing teams.

Graph Top Performers by Win Percentage:

Code Description: Using the arrange() and slice_head() functions from the dplyr package, this code selects the top 10 teams with the highest win percentages. It then creates a vertical bar plot using ggplot2, a data visualization package in R.

Insight: This visualization offers a straightforward comparison of win percentages among the top-performing teams. By focusing on the top 10 teams with the highest win percentages, it highlights those teams that have achieved notable success in terms of winning matches. The vertical bar plot allows for easy comparison of win percentages across these top-performing teams, enabling viewers to identify the most successful teams at a glance.

library(ggplot2)
library(dplyr)
library(tidyr)  # Load the tidyr package

# Assuming your dataset is named 'merged_data' and has columns 'TEAM' for team names, 'W' for wins, and 'L' for losses
# First, calculate the total number of wins and losses for each team
team_wins_losses <- merged_data %>%
  group_by(TEAM) %>%
  summarize(Total_Wins = sum(W, na.rm = TRUE),
            Total_Losses = sum(L, na.rm = TRUE))

# Assuming you have already calculated the top teams with the most wins
top_teams <- merged_data %>%
  group_by(TEAM) %>%
  summarize(Total_Wins = sum(W, na.rm = TRUE)) %>%
  arrange(desc(Total_Wins)) %>%
  top_n(10, Total_Wins) # Selects the top 10 teams with the most wins

# Filter team_wins_losses to include only the top teams
top_teams_wins_losses <- filter(team_wins_losses, TEAM %in% top_teams$TEAM)

# Convert data to long format for plotting
top_teams_wins_losses_long <- top_teams_wins_losses %>%
  pivot_longer(cols = c(Total_Wins, Total_Losses),
               names_to = "Outcome",
               values_to = "Count")

# Plot the stacked bar chart
ggplot(top_teams_wins_losses_long, aes(x = reorder(TEAM, -Count), y = Count, fill = Outcome)) +
  geom_bar(stat = "identity") +
  labs(title = "Win and Loss Ratio of Top Teams",
       x = "Team",
       y = "Count",
       fill = "Outcome") +
  theme_minimal() +
  coord_flip()

Graph Distribution of Win Percentage

Code Description: This code leverages the powerful ggplot2 library to craft a histogram that vividly illustrates the distribution of win percentages among the teams contained in our merged_data dataset. By specifying the win percentage (WIN%) as the variable for the x-axis, the code constructs a histogram with bins of width 0.05. Each bin effectively captures a range of win percentages, and the height of each corresponding bar indicates the frequency of teams found within that particular range. The aesthetic appeal of the histogram is enhanced with a soothing sky-blue fill color for the bars, complemented by sharp black borders that define each bar. Furthermore, the plot is polished with a minimalist theme, ensuring clarity and focus.

Insight: This visual representation of the win percentage distribution provides valuable insights into the landscape of team performance within our dataset. Examining the histogram allows us to discern patterns and trends in how win percentages are distributed across different teams. Peaks in the histogram highlight ranges where win percentages are more concentrated, indicating areas of strong performance or competitiveness among teams. Conversely, valleys in the histogram represent ranges where win percentages are less common, suggesting areas of weaker performance or greater variability. By gaining a holistic view of the win percentage distribution, stakeholders can make informed decisions and assessments regarding team performance, whether in sports analytics, organizational evaluations, or similar domains.

library(ggplot2)
ggplot(merged_data, aes(x = `WIN%`)) +
  geom_histogram(binwidth = 0.05, fill = "skyblue", color = "black") +
  labs(title = "Distribution of Win Percentage",
       x = "Win Percentage",
       y = "Frequency") +
  theme_minimal()