# Plot 3 density plots in the same graph, showing also standard deviation limits in each one

I have obtained from a paper next results:

Variable 1: Mean=165, sd=15

Variable 2: Mean=149, sd=18

Variable 3: Mean=134, sd=25

I have simulated normal distributions using rnorm. This is the way (with a n=1000): rnorm(1000,165,15). The same procedure with the others.

So now I want a common graph that shows the 3 normal distributions (density plots) at the same time. And also, that each of the density plots shows standard deviations bounds (1 and 2 sigmas) and if possible, means. This may be represented as vertical lines from the X axis til the curve of the plot.

Anybody knows which is the exact code in R?

• you could just draw the densities - you don't need simulated values. Try the following and check the various arguments (and examples, where relevant) - ?dnorm, ?curve, ?lines, ?segments, ?abline. – Glen_b -Reinstate Monica Nov 13 '13 at 11:32
• Also see ?density and in particular plot(density) – Peter Flom - Reinstate Monica Nov 13 '13 at 11:48
• I have been trying to get the exact code for two days but with no succeed. Could you please help me writing exactly the code I need? Thanks in advance – Mario Modesto Nov 13 '13 at 11:56

x<-0:300

a<-dnorm(x,165,15)
b<-dnorm(x,149,18)
c<-dnorm(x,134,25)

plot(x,a, type="l", lwd=3, ylim=c(0,1.2*max(a,b,c)), ylab="Probability Density")
segments(150,0, 150, a[which(x==150)], lwd=3, lty=2)
segments(180,0, 180, a[which(x==180)], lwd=3, lty=2)
text(165, a[which(x==165)], "165", pos=3)

lines(x,b, type="l", lwd=3, col="Red")
segments(131,0, 131, b[which(x==131)], lwd=3, lty=2, col="Red")
segments(167,0, 167, b[which(x==167)], lwd=3, lty=2, col="Red")
text(149, b[which(x==149)], "149", col="Red", pos=3)

lines(x,c, type="l", lwd=3, col="Blue")
segments(109,0, 109, c[which(x==109)], lwd=3, lty=2, col="Blue")
segments(159,0, 159, c[which(x==159)], lwd=3, lty=2, col="Blue")
text(134, b[which(x==134)], "134", col="Blue", pos=3)

• @MarioModesto, you might consider accepting Flask's answer (green checkmark under the vote arrows). Tks – Andre Silva Nov 17 '13 at 18:51