library(readr)
library(plotly)

hr <- read_csv(
  "https://raw.githubusercontent.com/aiplanethub/Datasets/refs/heads/master/HR_comma_sep.csv",
  show_col_types = FALSE
)

1. Histogram

plot_ly(hr, x = ~satisfaction_level, type = "histogram",
        marker = list(color = "steelblue")) %>%
  layout(
    title = "Employee Satisfaction Clusters Around Moderate to High Levels",
    xaxis = list(title = "Satisfaction Level"),
    yaxis = list(title = "Number of Employees")
  )

Analysis: Most employees have moderate to high satisfaction levels, though a smaller group of employees show very low satisfaction.

2. Box Plot

plot_ly(hr, y = ~last_evaluation, type = "box",
        marker = list(color = "darkorange")) %>%
  layout(
    title = "Most Employees Receive High Evaluation Scores",
    yaxis = list(title = "Last Evaluation Score")
  )

Analysis: Employee evaluation scores are generally high overall, with most values clustered toward the upper end of the scale.

3. Comparative Box Plot

plot_ly(hr,
        x = ~Department,
        y = ~average_montly_hours,
        type = "box",
        color = ~Department) %>%
  layout(
    title = "Average Monthly Work Hours Vary Significantly Across Departments",
    xaxis = list(title = "Department"),
    yaxis = list(title = "Average Monthly Hours")
  )
## Warning in RColorBrewer::brewer.pal(max(N, 3L), "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors
## Warning in RColorBrewer::brewer.pal(max(N, 3L), "Set2"): n too large, allowed maximum for palette Set2 is 8
## Returning the palette you asked for with that many colors

The distribution of average monthly working hours varies across departments, indicating differences in workload.

4. Pie Chart

attrition_salary <- hr[hr$left == 1, ] |>
  dplyr::count(salary)
plot_ly(attrition_salary,
        labels = ~salary,
        values = ~n,
        type = "pie") %>%
  layout(
    title = "Employee Attrition Appears Higher Among Lower Salary Levels"
  )

Analysis: A larger share of employees who left the company are in the lower salary category, suggesting salary may influence attrition.

5. Bar Plot

avg_satisfaction <- hr |>
  dplyr::group_by(Department) |>
  dplyr::summarise(avg_satisfaction = mean(satisfaction_level))
plot_ly(avg_satisfaction,
        x = ~Department,
        y = ~avg_satisfaction,
        type = "bar",
        marker = list(color = "steelblue")) %>%
  layout(
    title = "Average Employee Satisfaction Differs Across Departments",
    xaxis = list(title = "Department"),
    yaxis = list(title = "Average Satisfaction Level")
  )

Analysis: Average employee satisfaction differs between departments, showing that workplace experience may vary by department.