Task 1: Create a histogram for ‘satisfaction_level’ using plotly

plot_ly(hr, x = ~satisfaction_level, type = "histogram") %>%
  layout(title = "Distribution Employee Satisfaction: 
         Most Employees Have Moderate Satisfaction",
         xaxis = list(title = "Satisfaction Level"),
         yaxis = list(title = "Count"))

Insight: The histogram shows that the majority of employees have moderate satisfaction levels, with fewer employees having very high or very low satisfaction.

Task 2: Create a box plot for ‘last_evaluation’ using plotly

plot_ly(hr, y = ~last_evaluation, type = "box") %>%
  layout(title = "Box Plot of Last Evaluation Scores: Wide Range of Evaluation Performance",
         yaxis = list(title = "Last Evaluation Score"))

Insight: The box plot shows a wide range of evaluation scores among employees, with most employees scoring between 0.6 and 0.85, indicating variable performance.

Task 3: Create a comparative box plot for ‘average_montly_hours’ grouped by ‘department’

plot_ly(hr, x = ~Department, y = ~average_montly_hours, type = "box") %>%
  layout(title = "Comparison of Monthly Hours by Department: R&D \n and Sales Have Higher Variability",
         xaxis = list(title = "Department"),
         yaxis = list(title = "Average Monthly Hours"))

Insight: Departments like R&D and Sales show greater variability in working hours compared to other departments, indicating that some employees work significantly more than others.

Create a frequency table for attrition by salary

attrition_salary <- hr %>% 
  filter(left == 1) %>% 
  count(salary)

Task 4: Create a pie chart for ‘left’ grouped by ‘salary’

plot_ly(attrition_salary, labels = ~salary, values = ~n, type = 'pie') %>%
  layout(title = "Attrition by Salary Level: High Attrition in Low Salary Group")

Insight: The pie chart reveals that most employees who left the company had a low salary, indicating a potential relationship between low salary and high turnover.

Calculate average satisfaction by department

avg_satisfaction <- hr %>%
  group_by(Department) %>%
  summarise(avg_satisfaction = mean(satisfaction_level))

Task 5: Create a bar plot for average satisfaction by department using plotly

plot_ly(avg_satisfaction, x = ~Department, y = ~avg_satisfaction, type = 'bar') %>%
  layout(title = "Average Satisfaction by Department: HR and \n Management Show Lower Satisfaction",
         xaxis = list(title = "Department"),
         yaxis = list(title = "Average Satisfaction Level"))

Insight: Employees in HR and Management departments show lower average satisfaction levels compared to other departments like R&D and Sales.