Jacob Stoughton and Jakub Kepa

Starter Code

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
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.

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

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
plot_ly(hr, x = ~satisfaction_level, type = "histogram") %>%
  layout(title = "Most Employees Have Moderate (>0.5) Satisfaction Levels",
         xaxis = list(title = "Employee Satisfaction"),
         yaxis = list(title = "Count"))

Analysis: The majority of employee satisfaction is between 0.5-1, however there is a significant number (approximately 6%) who have a very low satisfaction level

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 Receive Good Evaluation Scores",
         yaxis = list(title = "Evaluation Scores"))

Analysis: The plot shows that most evaluation scores are between 0.55 and 0.85, but there may be outliers as high as 1 and lower than 0.4

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 = ~as.factor(Department), y = ~average_montly_hours, type = "box") %>%
  layout(title = "Average Monthly Hours are Mostly Between 150 and 250 For All Departments",
         xaxis = list(title = "Department"),
         yaxis = list(title = "Average Monthly Hours"))

Analysis: the majority of departments monthly hours are between 150 and 250. The accounting and R and D have slightly higher hours than the others, while the marketing department appears to have the lowest.

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_by_salary <- hr %>%
  filter(left==1) %>%
  group_by(salary,left) %>%
  summarise(count = n(), .groups = 'drop')
plot_ly(attrition_by_salary, 
        labels = ~salary, 
        values = ~count, 
        type = 'pie',
        textposition = 'inside',
        textinfo = 'label+percent',
        hoverinfo = 'text',
        text = ~paste(salary, '<br>Count:', count),
        marker = list(line = list(color = '#FFFFFF', width = 2))) %>%
  layout(title = list(text = "Lower Employee Salaries Have Higher Turnover",
                      x = 0.5,
                      xanchor = 'center'),
         showlegend = TRUE)

Analysis: Lower Salary levels have more change in personnel, whereas high salary levels have barely any turnover in jobs

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) %>% summarise(avg_satisfaction = mean(satisfaction_level))
plot_ly(avg_satisfaction, x = ~factor(Department), y = ~avg_satisfaction, type = 'bar') %>%
  layout(title = 'All Departments Have Moderate (>0.5) Satisfaction Levels',
         xaxis = list(title = 'Department'),
         yaxis = list(title = 'Average Satisfaction'))

Analysis: The average satisfaction levels for the departments are all very close, around 0.6. Accounting has the lowest average satisfaction level, while management has the highest