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.
install.packages("ggplot2", repos = "https://cran.rstudio.com/")
## 
## The downloaded binary packages are in
##  /var/folders/q1/gl10h4f94b3dsmnpk2jdysgr0000gn/T//RtmpB8mjKY/downloaded_packages
library(ggplot2)

Satisfaction level vs Average Monthly Hours Worked

cor.test(hr$average_montly_hours, hr$satisfaction_level)
## 
##  Pearson's product-moment correlation
## 
## data:  hr$average_montly_hours and hr$satisfaction_level
## t = -2.4556, df = 14997, p-value = 0.01408
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.036040356 -0.004045605
## sample estimates:
##         cor 
## -0.02004811
ggplot(hr, aes(x = average_montly_hours, y = satisfaction_level)) +
  geom_point() +
  geom_smooth(method = "lm", se = FALSE, color = "red") +
  labs(title = "Scatter Plot: Satisfaction level vs Average Monthly Hours Worked",
       x = "Average Monthly Hours",
       y = "Satisfaction Level")
## `geom_smooth()` using formula = 'y ~ x'

Number of Projects by Time at the Company

cor.test(hr$number_project, hr$time_spend_company)
## 
##  Pearson's product-moment correlation
## 
## data:  hr$number_project and hr$time_spend_company
## t = 24.579, df = 14997, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.1813532 0.2121217
## sample estimates:
##       cor 
## 0.1967859
ggplot(hr, aes(x = factor(time_spend_company), y = number_project)) +
  geom_boxplot(fill = "skyblue") +
  labs(title = "Box Plot: Number of Projects by Time at the Company",
       x = "Time Spent at Company",
       y = "Number of Projects") +
  theme_minimal()

Satisfaction Level by Time Spent at the Company

cor.test(hr$satisfaction_level, hr$time_spend_company)
## 
##  Pearson's product-moment correlation
## 
## data:  hr$satisfaction_level and hr$time_spend_company
## t = -12.416, df = 14997, p-value < 2.2e-16
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  -0.11668153 -0.08499948
## sample estimates:
##        cor 
## -0.1008661
ggplot(hr, aes(x = factor(time_spend_company), y = satisfaction_level)) +
  geom_boxplot(fill = "skyblue") +
  labs(title = "Box Plot: Satisfaction level by Time Spent at the Company",
       x = "Time Spent at Company",
       y = "Satisfaction level") +
  theme_minimal()

Satisfaction Level by Recent Promotion

cor.test(hr$promotion_last_5years, hr$satisfaction_level)
## 
##  Pearson's product-moment correlation
## 
## data:  hr$promotion_last_5years and hr$satisfaction_level
## t = 3.1367, df = 14997, p-value = 0.001712
## alternative hypothesis: true correlation is not equal to 0
## 95 percent confidence interval:
##  0.009605315 0.041591949
## sample estimates:
##        cor 
## 0.02560519
ggplot(hr, aes(x = factor(promotion_last_5years), y = satisfaction_level)) +
  geom_boxplot(fill = "skyblue") +
  labs(title = "Box Plot: Satisfaction level by Recent Promotion",
       x = "Promotion in last 5 Years",
       y = "Satisfaction level") +
  theme_minimal()