1. histogram - distribution of employee satisfaction
hr <- read.csv('https://raw.githubusercontent.com/aiplanethub/Datasets/refs/heads/master/HR_comma_sep.csv')
# satisfaction level
ggplot(hr, aes(x = satisfaction_level)) +
geom_histogram(binwidth = 0.1, fill = "steelblue", color = "black") +
labs(title = "Distribution of Employee Satisfaction",
x = "Satisfaction Level", y = "Count") +
theme_minimal()

2. box plot - last evaluation scores
# last evaluation scores
ggplot(hr, aes(y = last_evaluation)) +
geom_boxplot(fill = "tomato", color = "black") +
labs(title = "Distribution of Last Evaluation Scores",
y = "Last Evaluation Score") +
theme_minimal()

3. comparative box plot - monthly hours by department
# monthly hours by department
ggplot(hr, aes(x = Department, y = average_montly_hours, fill = Department)) +
geom_boxplot() +
labs(title = "Monthly Hours by Department",
x = "Department", y = "Average Monthly Hours") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))

4. pie chart of frequencies - attrition by salary level
# prep data
salary_attrition <- hr %>%
filter(left == 1) %>%
group_by(salary) %>%
summarise(count = n())
# attrition by salary level
pie(salary_attrition$count, labels = salary_attrition$salary,
main = "Attrition by Salary Level", col = c("lightblue", "pink", "lightgreen"))

5. bar plot of averages - average satisfaction by department
# average satisfaction by department
avg_satisfaction <- hr %>%
group_by(Department) %>%
summarise(avg_satisfaction = mean(satisfaction_level))
ggplot(avg_satisfaction, aes(x = Department, y = avg_satisfaction, fill = Department)) +
geom_bar(stat = "identity") +
labs(title = "Average Satisfaction by Department",
x = "Department", y = "Average Satisfaction Level") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
