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
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.3     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ lubridate 1.9.2     ✔ tibble    3.2.1
## ✔ purrr     1.0.2     ✔ tidyr     1.3.0
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks plotly::filter(), stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(ggcorrplot)

#Data

HR_comma_sep_2 <- read_csv("HR_comma_sep-2.csv")
## Rows: 14999 Columns: 10
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): sales, 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.

#Create a Box Plot for employee satisfaction and last evaluation, each broken out by the

#variable left. This meaning that for each variable there will be two box plots, side by side,

#where each box will represent the same variable, but one filtered for left = 0, and the other #left = 1

#Satisfaction vs left

graph_data1 <- HR_comma_sep_2 %>% 
  mutate(Left = ifelse(left == 0 , 'Stay' , 'Left'))



ggplot(graph_data1, aes(x = Left, y = satisfaction_level , 
                        fill = Left)) + 
  geom_boxplot() + 
  xlab("") + 
  ylab("Satisfaction Level") +
  theme(legend.position = "none")+ 
  ggtitle("Employees who stayed , on average,are more satisfied")

######Summary: The information supplied suggests that there may be a significant variation in job satisfaction between departing and remaining employees. More specifically, with an average score of 0.85, long-term employees report a higher level of satisfaction with the organization. On the other hand, the average satisfaction score of those who have opted to quit the organization is lower, at 0.70. This shows that job happiness and employee retention are positively correlated, underscoring the significance of creating an atmosphere at work that satisfies workers' needs and expectations in order to retain them as employees.

#last evaluation vs left

graph_data1 <- HR_comma_sep_2 %>% 
  mutate(Left = ifelse(left == 0 , 'Stay' , 'Left'))



ggplot(graph_data1, aes(x = Left, y = last_evaluation , 
                        fill = Left)) + 
  geom_boxplot() + 
  xlab("") + 
  ylab("Last Evaluation") +
  theme(legend.position = "none")+ 
  ggtitle("More employees, on average, left after the last evaluation")

######Summary: According to the data, employees who quit had higher scores (0.9) on their most recent work evaluation than those who continued their employment (0.85). This indicates that some workers chose to quit despite doing a great job at what they performed. It can be because they want a more difficult task, didn't feel valued, or didn't perceive opportunities to advance in their position. This indicates to employers that in order to retain top talent, they must ensure that they feel valued and have room to grow.

#Correlatio Matrix

hr_cor_data <- HR_comma_sep_2%>%
  select(1:5)
hr_cor_data <- cor(hr_cor_data)
ggcorrplot(hr_cor_data, 
           method = "square" ,
           type = 'lower' ,
           lab = T,
           colors = c("blue", "white", "orange"))

######Summary: The synopsis looks at the intricate connections between many aspects of the workplace and worker happiness. It turns out that job happiness tends to decrease when one is overburdened with projects, yet it is somewhat correlated with higher performance evaluation scores. Remarkably, there is a subtle relationship between the amount of hours worked each month and job satisfaction. More hours worked is linked to better performance ratings and more projects, but it has little direct effect on it. A subtle trade-off between tenure, workload, and contentment may also be seen as an employee's length of service, as a minor drop in satisfaction may be countered by a slight gain in evaluation scores and a rise in project workloads. In summary, these findings indicate that although performance reviews might increase contentment, workload and tenure have a more complex impact on an employee's general job satisfaction.