在R中画一条正态分布的横线

问题描述 投票:0回答:0

我想在曲线和直线的切点处画一条水平线

colorArea <- function(from, to, density, ...,col=NULL,  dens=NULL){
    y_seq <- seq(from, to, length.out=500)
    d <- c(0, density(y_seq, ...), 0)
    polygon( c(from, y_seq, to),d, col=col, density=dens)
}
curve(dnorm(x, mean=mu, sd=s), from = -10, to = 80, xlab="x", ylab="f(x)",xaxt='n')
#colorArea(from=mu-(s/2), to=mu+(s/2), dnorm, mean=mu, col=gray(0.8), sd=s,  dens=40)
abline(v=mu, col='red', lty=1)
abline(v=mu-(s), col='blue', lty=3)
abline(v=mu+(s), col='blue', lty=3)

legend("topright", legend = c("", ""), 
       title = expression(paste("N(",mu,",",sigma,")")),
      title.adj = 0, lty = 0, lwd = 0, box.lty = 0 )

axis(1, at=mu)
box()
r plot normal-distribution
© www.soinside.com 2019 - 2024. All rights reserved.