1. Histogram: Distribution of Employee Satisfaction Create a histogram of the satisfaction_level variable. The title should reflect a key takeaway from the distribution.

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.
plot_ly(hr, x = ~satisfaction_level, type = "histogram") %>%
  layout(title = "Most employees are satisfied (satisfaction > .5)",
         xaxis = list(title = "Satisfaction Level"),
         yaxis = list(title = "Frequency"))

- Most employees are satisfied (satisfaction > .5)

- About 6% of employees are extremely dissatisfied (satisfaction <= .11)

2. Box Plot: Last Evaluation Scores 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 = "Most employees have a strong evaluation score (evaluation > .7)", 
          xaxis = list(title = "Last Evaluation"),
          yaxis = list(title = "Score"))

- Half the employees have a strong evaluation score (evaluation > .72)

- 25% of employees have a weak evaluation score (evaluation < 0.56)

3. Comparative Box Plot: Monthly Hours by Department Create a comparative box plot of average_montly_hours grouped by department. The title should emphasize a significant difference or pattern among departments.

plot_ly(hr, y = ~average_montly_hours, type = "box") %>%
  layout(title = "Half the employees work an average of at least 200 hours/month", 
         xaxis = list(title = "Employees"),
         yaxis = list(title = "Average Monthly Hours"))

- Half the employees work an average of at least 200 hours per month

- 25% of employees work an average of 156 hours or less per month

4. Pie Chart of Frequencies: Attrition by Salary Level Create a pie chart showing the frequency of employee attrition (left) for each salary category. The title should point out the relationship between salary and attrition

left <- hr %>% filter(left == 1)
plot_ly(left, labels = ~salary,  type = 'pie') %>%
  layout(title = 'Most people who leave the company have low salaries')

- Around 2% of people who leave the company have high salaries

- Approximately 3 out of every 5 people who leave the company have low salaries

5. Bar Plot of Averages: Average Satisfaction by Department Create a bar plot displaying the average satisfaction_level for each department. The title should highlight a key observation about departmental satisfaction.

plot_ly(hr, x = ~mean(satisfaction_level), y = ~Department, type = 'bar') %>%
  layout(title = 'The Sales Department has the greatest satisfaction level',
         xaxis = list(title = 'Average Satisfaction Level'),
         yaxis = list(title = 'Department'))

- Sales’ satisfaction level is about 5x greater than product management

- About 75% of the data has a relatively low satisfaction level compared to the departments with the top 3 satisfaction levels