title: “Attrition Heatmap” author: “Sakshi Sharma_46” date: “2026-02-07” output: html_document
The objective of this analysis is to examine employee attrition patterns in relation to working hours and work-life balance (WLB), and to explore whether these patterns differ by gender. This helps HR managers identify high-risk groups and design targeted retention strategies.
A heatmap is chosen because it allows quick visual comparison of attrition rates across two categorical variables (hours worked and WLB). The use of color intensity highlights areas of concern, making patterns easy to spot at a glance.
This visualization is created using the ggplot2 package in R, which is commonly used to build clear and professional charts.
ggplot() is the starting point of the chart. It tells R which dataset to use and which variables represent working hours, work–life balance, and employee attrition. This step sets the foundation for the entire visualization.
geom_tile() is used to create the heatmap. It draws small rectangular blocks (tiles), where each block represents a specific combination of working hours and work–life balance. The color of each tile shows how high or low the attrition rate is.
geom_text() adds numerical values on top of the tiles. These values show the exact attrition percentage, making the heatmap easier to understand without guessing the numbers from colors alone.
scale_fill_gradient() controls the color scheme of the heatmap. Lighter colors represent lower attrition, while darker red shades represent higher attrition. This helps viewers quickly identify high-risk areas.
facet_wrap(~ gender) divides the heatmap into separate panels for male and female employees. This makes it easy to compare attrition patterns across genders and observe differences.
labs() is used to add a clear title, axis labels, and a legend title. These labels help the viewer understand what the chart represents without needing additional explanation.
theme_minimal() and theme() are applied to improve the visual appearance of the chart. They remove unnecessary background elements and adjust text and spacing, making the heatmap clean, readable, and professional.
#This interactive heatmap shows how attrition varies across different combinations of hours worked, work-life balance and gender.
#Attrition rate by Hours Worked,Work -Life balance and Gender