Adding text to a plot

前端 未结 1 486
一生所求
一生所求 2021-01-28 03:11
x <- seq(-3,3,0.01)
y1 <- dnorm(x,0,1)
y2 <- 0.5*dnorm(x,0,1)
plot(x,y1,type=\"l\",bty=\"L\",xlab=\"X\",ylab=\"dnorm(X)\")
points(x,y2,type=\"l\",col=\"red\")
p         


        
相关标签:
1条回答
  • 2021-01-28 03:24
    x <- seq(-3,3,0.01)
    y1 <- dnorm(x,0,1)
    y2 <- 0.5*dnorm(x,0,1)
    plot(x,y1,type="l",bty="L",xlab="X",ylab="dnorm(X)")
    points(x,y2,type="l",col="red")
    polygon(c(x,rev(x)),c(y2,rev(y1)),col="skyblue")
    
    idx <- which(x %in% -3:3)
    text(x[idx], y1[idx], labels = round(y1[idx], 2))
    text(x[idx], y2[idx], labels = round(y2[idx], 2), col="red")
    

    0 讨论(0)
提交回复
热议问题