library(wooldridge)
library(ggplot2)
data("ceosal1")
ceosal1$industry <- with(ceosal1, ifelse(indus == 1, "Industrial",
ifelse(finance == 1, "Finance",
ifelse(consprod == 1, "Consumer Products",
ifelse(utility == 1, "Utilities", "Other")))))
ceosal1$industry <- factor(ceosal1$industry,
levels = c("Industrial", "Finance",
"Consumer Products", "Utilities", "Other"))
# Task 1 - Scatterplot with trend line
ggplot(ceosal1, aes(x = sales, y = salary)) +
geom_smooth(method = "lm", se = TRUE,
color = "#2166AC", fill = "#AED6F1", linewidth = 1) +
geom_point(color = "#E74C3C", alpha = 0.65, size = 2.5) +
labs(
title = "CEO Salary vs. Company Sales",
subtitle = "ceosal1 dataset — Wooldridge",
x = "Firm Sales (millions of USD)",
y = "CEO Salary (thousands of USD)"
) +
theme_minimal()

# Task 2 - Faceted plot by industry
ggplot(ceosal1, aes(x = roe, y = salary)) +
geom_smooth(method = "lm", se = FALSE, color = "#27AE60", linewidth = 0.9) +
geom_point(color = "#8E44AD", alpha = 0.60, size = 2) +
facet_wrap(~ industry, ncol = 3, scales = "free_y") +
labs(
title = "CEO Salary vs. Return on Equity by Industry",
x = "Return on Equity (%)",
y = "CEO Salary (thousands of USD)"
) +
theme_minimal() +
theme(strip.text = element_text(face = "bold"))

# Task 3 - Color scale plot
ggplot(ceosal1, aes(x = sales, y = salary, color = roe)) +
geom_point(size = 3, alpha = 0.80) +
scale_color_viridis_c(name = "Return on\nEquity (%)", option = "C", direction = -1) +
labs(
title = "CEO Salary vs. Sales (Colored by ROE)",
x = "Firm Sales (millions of USD)",
y = "CEO Salary (thousands of USD)"
) +
theme_minimal()
