library(ggplot2)
# Data for the normal distribution
x_vals <- seq(-4, 4, length.out = 100)
y_vals <- dnorm(x_vals)
# Define critical value for p-value visualization
critical_value <- 2
# Create the first ggplot for the normal distribution with shaded p-value region
p_value <- ggplot(data = data.frame(x = x_vals, y = y_vals), aes(x = x, y = y)) +
geom_line(color = "#355c7d", size = 1) + # Normal distribution line
geom_area(data = subset(data.frame(x = x_vals, y = y_vals), x >= critical_value),
aes(x = x, y = y), fill = "#f67280", alpha = 0.5) + # Shaded p-value area
labs(title = "Normal Distribution with P-value Region",
x = "Test Statistic (z)", y = "Density") +
theme_minimal()
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.