library(readr)
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
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
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.
#Task 1:
plot_ly(hr,
x = ~satisfaction_level, type = "histogram") %>%
layout(title = "Most employees are satisfied (Satisfaction > 0.5)",
xaxis = list(title = "Satisfaction Level"),
yaxis = list(title = "Employees"))
Task 1 Analysis:
- Most employees are satisfied (Satisfaction > 0.5)
- There is a large group (6%) of extremely unsatisfied employees
(Satisfaction < 0.11)
#Task 2:
plot_ly(hr,
x = ~last_evaluation, type = "box") %>%
layout(title = "Most employees evaluation scores are above 0.5",
xaxis = list(title = "Last Evaluation"))
Task 2 Analysis:
- The box plot shows that most employees have evaluation scores
above 0.5, indicating good overall performance.
Task 3 Analysis:
- All departments have average monthly hours between 150 and 250
hours.
- The monthly work hours in each department are very consistent
across the board.
#Task 4:
attrition_data <- hr %>% filter(left == 1)
salary_attrition_counts <- attrition_data %>% count(salary)
plot_ly(salary_attrition_counts, labels = ~salary, values = ~n, type = 'pie')%>%
layout(title = 'Most of Employee Attrition (60%) comes from low salary employees')
Task 4 Analysis:
- Most of Employee Attrition (60%) comes from low salary
employees
- Very few employees (2.3%) with high salary leave the company
#Task 5:
plot_ly(hr, x = ~Department, y = ~satisfaction_level, type = 'bar') %>%
layout(
title = 'The sales department has the most highly satisfied employees',
xaxis = list(title = 'Department'),
yaxis = list(title = 'Satisfaction Level')
)
Task 5 Analysis:
- The sales department has the most highly satisfied employees
- Most other departments are not very satisfied