library(readr)
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(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
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_data <- hr %>%
  mutate(AttritionStatus = as.factor(ifelse(left == 0, 'Stayed', 'Left')))

##1. Box plot for Satisfaction Level

plot_ly(data = plot_data, 
        x = ~AttritionStatus, 
        y = ~satisfaction_level, 
        type = 'box') %>%
  layout(title = "Satisfaction Level by Attrition Status")

##2. Box plot for Last Evaluation

plot_ly(data = plot_data, 
        x = ~AttritionStatus, 
        y = ~last_evaluation, 
        type = 'box') %>%
  layout(title = "Last Evaluation by Attrition Status")

##3. Box plot for Average Monthly Hours

plot_ly(data = plot_data, 
        x = ~AttritionStatus, 
        y = ~average_montly_hours, 
        type = 'box') %>%
  layout(title = "Average Monthly Hours by Attrition Status")

##4. Box plot for Time Spent at Company

plot_ly(data = plot_data, 
        x = ~AttritionStatus, 
        y = ~time_spend_company, 
        type = 'box') %>%
  layout(title = "Time Spent at Company by Attrition Status")