library(readr)
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.
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
- Create a histogram of the satisfaction_level variable. The
title should reflect a key takeaway from the distribution.
plot_ly(hr, x = ~satisfaction_level, type = "histogram") %>%
layout(title = "Satisfaction Levels: Most Employees are Moderately Satisfied",
xaxis = list(title = "Satisfaction Level"),
yaxis = list(title = "Frequency"))
- Create a box plot of the last_evaluation variable. The title
should highlight an important insight about the evaluation
scores.
plot_ly(hr, y = ~last_evaluation, type = "box") %>%
layout(title = "Last Evaluation Scores: Most Employees Rate Above 0.5")
- Create a comparative box plot of average_montly_hours
grouped by department.
plot_ly(hr, x = ~Department, y = ~average_montly_hours, type = "box") %>%
layout(title = "Average Monthly Hours: Significant Variations Across Departments",
xaxis = list(title = "Department"),
yaxis = list(title = "Average Monthly Hours"))
- Create a bar plot displaying the average satisfaction_level
for each department.
attrition_salary <- table(hr$salary, hr$left)
attrition_counts <- attrition_salary[, "1"]
plot_ly(labels = names(attrition_counts), values = attrition_counts, type = 'pie') %>%
layout(title = "Attrition by Salary Category: Higher Salaries Tend to Reduce Attrition")
- Create a bar plot displaying the average satisfaction_level
for each department.
average_satisfaction <- aggregate(satisfaction_level ~ Department, data = hr, FUN = mean)
plot_ly(average_satisfaction, x = ~Department, y = ~satisfaction_level, type = 'bar') %>%
layout(title = "Satisfaction Level by Department: Similar Across Departments",
xaxis = list(title = "Department"),
yaxis = list(title = "Average Satisfaction Level"))