Load Libraries & Datasets

library(readr)
library(dplyr)
library(plotly)

hr <- read_csv('https://raw.githubusercontent.com/aiplanethub/Datasets/refs/heads/master/HR_comma_sep.csv')

Histogram:

plot_ly(hr, x = ~satisfaction_level, type = "histogram") %>%
  layout(
    title = "Most Employees Have Moderate to Low Satisfaction Levels (<0.5)",
    xaxis = list(title = "Satisfaction Level from 0 to 1"),
    yaxis = list(title = "Frequency of Employees")
  )
# Observation:
# The histogram shows that a significant number of employees have moderate to low satisfaction,
# with fewer reporting high satisfaction. This suggests a potential area for employee engagement initiatives.

Box Plot:

plot_ly(hr, y = ~last_evaluation, type = "box") %>%
  layout(
    title = "Evaluations Show High Scores with a Few Outliers (AVG > 0.7)",
    yaxis = list(title = "Most Recent Evaluation Score")
  )
# Observation:
# The box plot reveals generally high evaluation scores but with notable outliers at both extremes,
# possibly indicating under performing and exceptional employees who may require specific management strategies.

Comparative Box Plot:

plot_ly(hr, x = ~Department, y = ~average_montly_hours, type = "box") %>%
  layout(
    title = "Technical and Sales Departments Report Longer Monthly Hours",
    xaxis = list(title = "Department"),
    yaxis = list(title = "Average Monthly Hours")
  )
# Observation:
# Technical and Sales departments show longer average monthly hours, which could indicate higher workloads 
# or stress levels.
# Investigating these workloads further could help balance responsibilities across teams.

Pie Chart of Frequencies:

# Attrition data by salary level
attrition_data <- hr %>%
  filter(left == 1) %>%
  group_by(salary) %>%
  summarise(count = n()) %>%
  mutate(prop = count / sum(count))

plot_ly(attrition_data, labels = ~salary, values = ~count, type = 'pie', textinfo = 'label+" salary"+percent') %>%
  layout(
    title = "High Attrition Rates Among Lower Salary Employees (>50%)"
  )
# Observation:
# This pie chart reveals that employees with lower salaries have higher attrition rates,
# indicating that salary may play a crucial role in employee retention and satisfaction.

Bar Plot of Averages:

# Average satisfaction by department
satisfaction_data <- hr %>%
  group_by(Department) %>%
  summarise(avg_satisfaction = mean(satisfaction_level))

plot_ly(satisfaction_data, x = ~Department, y = ~avg_satisfaction, type = 'bar') %>%
  layout(
    title = "Accounting Department Reports the Lowest Satisfaction (0.58)",
    xaxis = list(title = "Department"),
    yaxis = list(title = "Average Satisfaction Level")
  )
# Observation:
# Accounting has the lowest average satisfaction among all departments, highlighting an area where 
# efforts to improve employee engagement can be beneficial.