Install Packages

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.
options(repos = c(CRAN = "https://cran.rstudio.com/"))
install.packages("plotly")
## 
## The downloaded binary packages are in
##  /var/folders/6q/3nbyz_h95ks8z6lqpx_k5x_40000gn/T//RtmpURzhCS/downloaded_packages
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

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

plot_ly(hr, x = ~satisfaction_level, type = "histogram") %>%
  layout(title = "Large Amount of Employees Have a Satisfaction Level of
0.1", 
    xaxis = list(title = "Satisfaction Level"), 
    yaxis = list(title =
"Count"))
#Large spike of employees at 0.1 represents a high number of employees with very low satisfaction. Outside of this, most employees seem to be relatively uniform above 0.4, with an outlier at 0.46.

Task 2: 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 = "Evaluation Scores Show High Variation, with Mean Close to 0.7",
    yaxis = list(title = "Last Evaluation Scores"))
#The median score is around 0.7, whcih means that on average, workers are having a good evaluations. Although we can tell from the graph that not all workers are just good, as it is a very large range, between 0.4 and 1.0.

Task 3: 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, y = ~average_montly_hours, x = ~Department, type = "box") %>% 
  layout(title = "Comparative Box Plot: Significant Pattern Across Departments for Monthly Hours Worked", 
    xaxis = list(title = "Department"), 
    yaxis = list(title = "Average Monthly Hours"))
#Every department has extremely similar boxplots compared to eachother. This means that the hours worked does not vary per department. Although, workers in every department can have a broad range in terms of workload,as every department has a range between around 100 and 300 hours worked per month. No correlation between department and workload.

Task 4: 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 %>% 
  group_by(salary, left) %>%
  summarise(count = dplyr::n(), .groups = 'drop') %>% 
  filter(left == 1)

plot_ly(attrition_by_salary, labels = ~salary, values = ~count, type ="pie", 
    textinfo = "label+percent", insidetextorientation = "radial",
    hoverinfo = 'label+value+percent') %>% 
  layout(title = "Attrition Rates by Salary Level: Higher Attrition Among Lower Salaries", 
    showlegend = TRUE)
#The majority of attrition seems to occur with low income employees and high income employees extremely rarely. This indicates that there is a strong correlation between having a lower wage and chance of turnover.

Task 5: 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_by_department <- hr %>% 
  group_by(Department) %>%
  summarise(avg_satisfaction = mean(satisfaction_level, na.rm = TRUE))

plot_ly(avg_satisfaction_by_department, x = ~Department, y = ~avg_satisfaction, type = 'bar') %>% 
  layout(title = "Average Satisfaction by Department: Minimal Variations Across Departments",
    xaxis = list(title = "Department"), 
    yaxis = list(title = "Average Satisfaction Level"))
#This chart suggests that employee satisfaction is relatively uniform across all departments, around 0.6. No correlation between department and satisfaction.