geom_line(aes(y = H0), color = "black", linewidth = 1.2) +
geom_line(aes(y = H1), color = "blue", linetype = "dashed", linewidth = 1.2) +
geom_area(data=subset(df, x > z_alpha), aes(y=H0), fill="red", alpha=0.4) +
geom_area(data=subset(df, x <= z_alpha), aes(y=H1), fill="blue", alpha=0.3) +
geom_vline(xintercept = z_alpha, linetype="dotted", color="black", linewidth=1) +
geom_segment(aes(x = 2.8, y = 0.13, xend = 2, yend = 0.05),
arrow = arrow(length = unit(0.2, "inches")),
color = "red", linewidth = 1) +
annotate("text", x=z_alpha+0.6, y=0.35, label="Reject H0", color="black") +
annotate("text", x=-1.9, y=0.3, label="Fail to Reject H0", color="black") + # moved left
annotate("text", x=3.2, y=0.145, label="Type I Error (α)", color="red") + # moved left and down
annotate("text", x=-0, y=0.05, label="Type II Error (β)", color="blue") +
labs(title="Type I and Type II Errors",
x="Test Statistic / Sample Mean",
y="Probability Density") +
theme_minimal(base_size = 12)