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.
  1. Histogram: Distribution of Employee Satisfaction
    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 = "About 50% of employees are satisfied (satisfaction > .7)",
         xaxis = list(title = "Satisfaction Level"),
         yaxis = list(title = "Count of Employees"))

Analysis:
a Around 50% of employees are satisfied (satisfied > 0.7)
b Around 10% of people are extremely dissatisfied (dissatisfied < 0.2)

  1. 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, x = ~last_evaluation, type = "box") %>%
  layout(title = "About 50% of Employees Scored Well on Last Evaluation (last_evalutation > 0.72)",
         xaxis = list(title = "Last Evaluation Score"),
         yaxis = list(title = "Number of Evaulations")) 

Analysis:
a The minimum score of 0.36 and maximum score of 1.00 indicates a broad range of performance levels.
b The median score being 0.72 implies that half of the employees have evaluation scores above this value.
c About 50% of employees scored between 0.56 and 0.87

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, x = ~Department, y = ~average_montly_hours, type = "box") %>%
  layout(title = "Consistent Work Hours Across Departments (Average_Monthly_Hours > 200)",
         xaxis = list(title = "Department"),
         yaxis = list(title = "Average Monthly Hours"))

Analysis:
a The highest highest median average is 204 from the management department
b The HR department had the lowest median average 197

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.

attrition_counts <- hr %>% count(salary, left)
plot_ly(attrition_counts %>% filter(left == 1), labels = ~salary, values = ~n, type = 'pie') %>%
  layout(title = 'People who recieve a low salary are the most likely to leave their jobs')

Analysis:
a People who recieve a high salary are least likely to leave their jobs with the lowest percentage of 2.3
b People who recieve a low salary are the most likely to leave their jobs, 60.8%, which over 50% of the data

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.

avg_satisfaction <- hr %>%
  group_by(Department) %>%
  summarize(avg_satisfaction = mean(satisfaction_level))

plot_ly(avg_satisfaction, x = ~Department, y = ~avg_satisfaction, type = 'bar') %>%
  layout(title = 'The management department is the most satisfied with a level < 0.62',
         xaxis = list(title = 'Department'),
         yaxis = list(title = 'Average Satisfaction Level'))

Anaylsis:
a The accounting department has the lowest average satisfaction level of 0.58
b The HR department has the second lowest average satisfaction level of 0.59