In this document, we will create a heatmap to visualize the number of wins and losses for different teams. The data has been processed to include the total number of wins and losses for each team, and we will use this information to generate a heatmap.
‘ggplot2’ is one of the most widely used packages for data visualization in R. Developed by “Hadley Wickham”, ‘ggplot2’ implements the grammer of graphics, a powerfull framework for creating complex and aesthetically pleasing visualizations. The package allows you to build plots layer by layer, starting with the data and mapping variables to visual properties, and then adding elements like geometries, scales, and themes.
ggplot2 allows you to map variables
in your dataset to visual properties such as position, color, size, and
shape.ggplot2 is highly extensible, allowing
users to create custom plots and themes.ggplot2 is
an essential tool for any R user looking to create data visualizations,
offering flexibility and control over the appearance of your plots.library(ggplot2)
library(reshape2)
library(reshape2): This command loads the reshape2 package, which provides tools for reshaping data between wide and long formats. The melt() function from this package will be used to prepare our data for the heatmap.
library(ggplot2): This command loads the ggplot2 package, which will be used to create the heatmap. ggplot2 allows us to build plots layer by layer, offering extensive customization options.
# Read the CSV file into a data frame
Icc_test_2024 <- read.csv("Icc_Test_2024.csv")
head(Icc_test_2024)
## X.1 X TEAMS M W L T D N.R PT PCT Series.Form Next
## 1 1 1 India 9 6 2 0 1 0 74 68.51 LWWWW vs BAN, BAN, NZ
## 2 2 2 Australia 12 8 3 0 1 0 90 62.50 WWLWW vs IND, IND, IND
## 3 3 3 New Zealand 6 3 3 0 0 0 36 50.00 WWWLL vs SL, SL, IND
## 4 4 4 Sri Lanka 4 2 2 0 0 0 24 50.00 LLWW vs ENG, ENG, ENG
## 5 5 5 Pakistan 5 2 3 0 0 0 22 36.66 WWLLL vs BAN, BAN, ENG
## 6 6 6 England 13 6 6 0 1 0 57 36.54 LLWWW vs SL, SL, SL
## Total_wins Total_lose
## 1 4 1
## 2 4 1
## 3 3 2
## 4 2 2
## 5 2 3
## 6 3 2
# Melt the data for heatmap
melted_data <- melt(Icc_test_2024[, c("TEAMS", "Total_wins", "Total_lose")], id.vars = "TEAMS")
# Create the heatmap
ggplot(melted_data, aes(x = TEAMS, y = variable, fill = value)) +
geom_tile() +
labs(title = "Heatmap of Wins and Losses",
x = "Teams", y = "Outcome") +
scale_fill_gradient(low = "lightblue", high = "darkblue") + # Improved color scheme
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5)) # Center the title
This heatmap provides a clear visual representation of the number of wins and losses for each team. By using a gradient color scale, the differences in performance across teams are easily distinguishable, helping to identify which teams have the most consistent records. The ‘ggplot2’ package makes it easy to create such visualizations, offering a range of customization options to tailor the plot to your specific needs.