library(readr)
library(dplyr)
##
## 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
library(plotly)
## Loading required package: ggplot2
##
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
##
## last_plot
## The following object is masked from 'package:stats':
##
## filter
## The following object is masked from 'package:graphics':
##
## layout
load dataset
hr <- read_csv("https://raw.githubusercontent.com/aiplanethub/Datasets/refs/heads/master/HR_comma_sep.csv")
## Rows: 14999 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): Department, salary
## dbl (8): satisfaction_level, last_evaluation, number_project, average_montly...
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
1. Histogram: Distribution of Employee Satisfaction
plot_ly(
data = hr,
x = ~satisfaction_level,
type = "histogram"
) |>
layout(
title = "Employee Satisfaction: Most Employees Report Moderate to High Satisfaction",
xaxis = list(title = "Satisfaction Level (0–1)"),
yaxis = list(title = "Count of Employees")
)
The distribution is right-skewed, with many employees reporting
satisfaction above 0.6. Very low satisfaction (<0.3) is relatively
rare, affecting a small subset of workers. This suggests overall
positive morale, which may correlate with lower turnover in most of the
workforce.
2. Box Plot: Last Evaluation Scores
plot_ly(
data = hr,
y = ~last_evaluation,
type = "box",
boxpoints = "outliers"
) |>
layout(
title = "Last Evaluation Scores: Generally High With Some Low Outliers",
yaxis = list(title = "Evaluation Score (0–1 Scale)")
)
The median evaluation score is high (~0.85), indicating strong
performance among employees. The tight IQR suggests relatively
consistent performance across workers. A few low outliers indicate a
minority of employees may be underperforming and require support.
3. Comparative Box Plot: Monthly Hours by Department
plot_ly(
data = hr,
x = ~Department,
y = ~average_montly_hours,
type = "box"
) |>
layout(
title = "Monthly Working Hours by Department: Noticeable Variability in Workload",
xaxis = list(title = "Department"),
yaxis = list(title = "Average Monthly Hours")
)
Departments such as technical and sales show slightly higher median
working hours. Some departments display wide ranges, suggesting uneven
workload distribution within teams. Overworked departments may face
increased stress, lower satisfaction, or higher turnover risks.
4. Pie Chart: Attrition by Salary Level
left_data <- hr[hr$left == 1, ]
salary_counts <- table(left_data$salary)
plot_ly(
labels = names(salary_counts),
values = as.numeric(salary_counts),
type = "pie"
) |>
layout(
title = "Attrition by Salary Level: Lower Salaries Strongly Associated With Turnover",
showlegend = TRUE
)
Employees with low salaries account for roughly 60% of total
turnover. Very few high-salary employees leave, suggesting compensation
is an important retention mechanism. Medium-salary departures show that
factors beyond pay also influence turnover (culture, workload, growth
opportunities).
5. Bar Plot: Average Satisfaction by Department
dept_satisfaction <- hr |>
group_by(Department) |>
summarise(avg_satisfaction = mean(satisfaction_level, na.rm = TRUE)) |>
arrange(Department)
plot_ly(
data = dept_satisfaction,
x = ~Department,
y = ~avg_satisfaction,
type = "bar"
) |>
layout(
title = "Average Satisfaction by Department:
Small but Meaningful Differences in Morale",
xaxis = list(title = "Department"),
yaxis = list(title = "Average Satisfaction Level"),
bargap = 0.2
)
Average satisfaction is consistently moderate-to-high (~0.55–0.65)
across all departments. Departments such as sales and support show
slightly lower averages, which may contribute to turnover or burnout.
Overall consistency suggests a generally positive organizational
culture, despite higher workloads in some areas.
Key Takeaways from the Visualizations
Employees generally report high satisfaction and strong evaluations,
indicating a capable workforce. A few departments carry heavier workload
burdens, which may influence morale and retention. Low-salary employees
are most likely to leave, confirming the role of compensation in
turnover. Departmental satisfaction levels are similar, though small
variations may signal areas for intervention.
Organizational Implications
Improving compensation for low-salary workers may significantly
reduce attrition. Monitoring workload distribution could help prevent
burnout in high-hour departments. Supporting low performers through
training or coaching may improve efficiency and morale.