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 = "About 50% of Employees are Satisfied (satisfaction > .7)",
         xaxis = list(title = "Satisfaction Level"),
         yaxis = list(title = "Count of Employees"))

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 = "Average Evaluation Scores",
         yaxis = list(title = "Employee Scores"))

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, 
        x = ~Department,       
        y = ~average_montly_hours, 
        type = "box") %>%
  layout(title = "Differences in Monthly Hours",
         xaxis = list(title = "Department"),
         yaxis = list(title = "Average Monthly Hours"))

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.

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

plot_ly(atr_sal, 
        labels = ~salary, 
        values = ~n, 
        type = "pie") %>%
  layout(title = "Relationship between Salary and Employee Attrition",
         xaxis = list(title = "Salary Category"),
         yaxis = list(title = "Attrition Frequency"))

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_sat_dep <- hr %>% 
  group_by(Department) %>% 
  summarise(satisfaction_level = mean(satisfaction_level))

plot_ly(avg_sat_dep, 
        x = ~Department, 
        y = ~satisfaction_level, 
        type = "bar", 
        stat = "summary", 
        fun = "mean") %>%
  layout(title = "Average Satisfaction Level by Department",
         xaxis = list(title = "Department"),
         yaxis = list(title = "Average Satisfaction Level"))