Task 1
p_wrap <- ggplot(penguins, aes(x = bill_length_mm, fill = species)) +
geom_histogram(alpha = 0.7, bins = 20, color = "black") +
facet_wrap(~species) +
labs(
title = "Distribution of Bill Length by Species",
x = "Bill Length (mm)",
y = "Count"
) +
theme_minimal() +
theme(legend.position = "none")
p_wrap

p_grid <- ggplot(penguins, aes(x = bill_length_mm, y = bill_depth_mm, color = species)) +
geom_point(alpha = 0.7) +
facet_grid(sex ~ species) +
labs(
title = "Bill Dimensions by Species and Sex",
x = "Bill Length (mm)",
y = "Bill Depth (mm)"
) +
theme_minimal()
p_grid

Task 2
p1 <- ggplot(penguins, aes(bill_length_mm, bill_depth_mm, color = species)) +
geom_point(alpha = 0.7) +
theme_minimal()
p2 <- ggplot(penguins, aes(species, fill = species)) +
geom_bar() +
theme_minimal() +
theme(legend.position = "none")
p3 <- ggplot(penguins, aes(flipper_length_mm, fill = species)) +
geom_density(alpha = 0.5) +
theme_minimal()
side_by_side <- p1 + p2 + p3 + plot_layout(guides = "collect")
side_by_side

stacked <- p1/ p2 / p3 + plot_layout(guides = "collect")
stacked

unequal <- (p1 + p2) / p3 + plot_layout(heights = c(2, 1), guides = "collect")
unequal

Task 3
ggsave("combined_figure.png", unequal, width = 10, height = 8, dpi = 300)
ggsave("combined_figure.pdf", unequal, width = 10, height = 8)
write.csv(penguins, "penguins_data.csv", row.names = FALSE)