EX. 以 x ~N(0,1), P(x<-1.4) 为例
library(ggplot2)
plot_area <- function(min,max){
function(x){
y <- dnorm(x)
y[x<min | x>max] <-NA
return(y)
}
}
pnorm(-1.4) #p-value
ggplot(data.frame(x=c(-4,4)), aes(x=x)) +
theme_bw() +
stat_function(fun=plot_area(-4, -1.4), geom="area", fill="red", alpha=0.2) +
stat_function(fun=dnorm) +
geom_text(aes(y=0, x=c(-1.4),label=paste("x=",c(-1.4)), vjust=1))