dnorm_segment <- function(x, min = 0, max = 1) dnorm(x)*ifelse(x>=min & x<=max, 1, NA)
zero_segment <- function(x, min = 0, max = 1) ifelse(x>=min & x<=max, 0, NA)
plot_both <- function(min, max, colour)
{
args <- list(min = min, max = max)
list(
stat_function(fun = dnorm_segment, col = colour, size = 3, args = args, n = 1001),
stat_function(fun = zero_segment, col = colour, size = 3, args = args, n = 1001)
)
}
ggplot(data.frame(x = c(-3, 3)), aes(x)) +
stat_function(fun = dnorm) +
plot_both(-3, -2, "purple") +
plot_both(-2, -1, "yellow")
# + etc