R Markdown

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"))
- “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, y = ~last_evaluation, type = "box") %>%
  layout(title = "Diversity with Evaluation Scores ",
         yaxis = list(title = "Last Evaluation"))
-“25% of employees received an excellent evaluation score (>0.87)”
-“25% of employees received poor evaluation scores (<0.56)”

Task 3

plot_ly(hr, x = ~as.factor(Department), y = ~average_montly_hours, type = "box") %>%
  layout(title = "Comparative Monthly Hours Across Departments",
         xaxis = list(title = "Department"),
         yaxis = list(title = "Average Monthly Hours"))
- “No department is working more than 310 hours”
- “Management works the most 204 average monthly hours”

Task 4

attrition_counts <- hr %>%
  group_by(salary) %>%
  summarise(attrition_count = sum(left))

plot_ly(attrition_counts, labels = ~salary, values = ~attrition_count, type = 'pie') %>%
  layout(title = "Impact of Salary Level on Employee Attrition",
         showlegend = TRUE)
- “Employees with a low salary are the most likely to leave the company (60.8%)”
-“Employees who are receiving a high salary are extremely unlikely to leave the company (2.3%)”

Task 5

avg_satisfaction <- hr %>%
  group_by(Department) %>%
  summarise(avg_satisfaction = mean(satisfaction_level))
plot_ly(avg_satisfaction, x = ~factor(Department), y = ~avg_satisfaction, type = 'bar') %>%
  layout(title = 'Average Satisfaction Level by Department',
         xaxis = list(title = 'Department'),
         yaxis = list(title = 'Average Satisfaction Level'))
- “hr and accounting are the only two departments with a low satisfaction level (<0.6)”
- “There is not a large difference in average satisfaction between all departments (0.582 - 0.621)”