library(ggplot2)
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)
library(plotly)
## 
## 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.
p1 <- ggplot(hr, aes(x = satisfaction_level)) +
  geom_histogram(binwidth = 0.05, fill = "blue", color = "black", alpha = 0.7) +
  labs(title = "Most Employees Have a Satisfaction Level Below 0.6",
       x = "Satisfaction Level",
       y = "Count") +
  theme_minimal()
ggplotly(p1)
p2 <- ggplot(hr, aes(y = last_evaluation)) +
  geom_boxplot(fill = "orange", color = "black") +
  labs(title = "Most Employee Evaluations Are Above 0.5, Some Outliers Exist",
       y = "Last Evaluation Score") +
  theme_minimal()
ggplotly(p2)
p3 <- ggplot(hr, aes(x = Department, y = average_montly_hours, fill = Department)) +
  geom_boxplot() +
  labs(title = "Some Departments Work More Hours Than Others",
       x = "Department",
       y = "Average Monthly Hours") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
ggplotly(p3)
attrition_salary <- hr %>%
  group_by(salary) %>%
  summarise(left_count = sum(left)) 

p4 <- plot_ly(attrition_salary, labels = ~salary, values = ~left_count, type = 'pie') %>%
  layout(title = "Higher Attrition Rates Among Low Salary Employees")
p4
avg_satisfaction <- hr %>%
  group_by(Department) %>%
  summarise(avg_satisfaction = mean(satisfaction_level))

p5 <- ggplot(avg_satisfaction, aes(x = reorder(Department, -avg_satisfaction), y = avg_satisfaction, fill = Department)) +
  geom_bar(stat = "identity") +
  labs(title = "Departments Differ in Satisfaction Levels",
       x = "Department",
       y = "Average Satisfaction Level") +
  theme_minimal() +
  theme(axis.text.x = element_text(angle = 45, hjust = 1))
ggplotly(p5)