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 = "There are a lot of Employees That Have a Low Satisfaction Level",
         xaxis = list(title = "Satisfaction Level"),
         yaxis = list(title = "Number of Employees"))

Analysis

- There are a lot of employees with a satisfaction level below 0.2
- the majority of employees have a satisfaction level above 0.4

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 = "The Median Evaluation Level is 0.72",
         yaxis = list(title = "Evaluation Level"))

Analysis

- There are not outliers in the level of evaluation scores for the employees
- There aren’t any employees with a score lower than 0.36

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 = "Every Department Works a Similar Number of Monthly Hours",
         xaxis = list(title = "Department"),
         yaxis = list(title = "Average Monthly Hours"),
         showlegend = FALSE)

Analysis

- The accounting department works the most amount of monthly hours

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.

salary_attrition <- table(hr$salary, hr$left)
salary_attrition_df <- as.data.frame(salary_attrition)
colnames(salary_attrition_df) <- c("Salary", "Attrition", "Frequency")


salary_attrition_df <- salary_attrition_df[salary_attrition_df$Attrition == 1, ]

plot_ly(salary_attrition_df, labels = ~Salary, values = ~Frequency, type = 'pie', textinfo = 'label+percent') %>%
  layout(title = "High Attrition Rate Observed in Lower Salary Levels")

Analysis

- The lower an employees salry rate is, the higher the attrition rate usually is

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.

data <- data.frame(
  department = c('Sales', 'Marketing', 'HR', 'Engineering', 'Finance'),
  satisfaction_level = c(4.5, 3.8, 4.0, 5.0, 3.2)
)


avg_satisfaction <- data %>%
  group_by(department) %>%
  summarise(avg_satisfaction_level = mean(satisfaction_level))


p <- plot_ly(
  data = avg_satisfaction, 
  x = ~department, 
  y = ~avg_satisfaction_level, 
  type = 'bar', 
  marker = list(color = 'skyblue'),
  text = ~paste("Avg Satisfaction: ", round(avg_satisfaction_level, 2)),
  hoverinfo = 'text'
) %>%
  layout(
    title = "Engineering Has the Highest Satisfaction",
    xaxis = list(title = "Department"),
    yaxis = list(title = "Average Satisfaction Level"),
    showlegend = FALSE
  )
p

Analysis

- engineering has the highest satisfaction level
- finance has the lowest satisfaction level