# Two tailed normal curve completely labeled

I am trying to generate a normal curve centered at 95 with Standard deviation 2. This normal curve needs to have 2 blue 2.5% of area under the curve and one region where 95% of the area is in the middle and red. I am trying to do this using only variables but cannot mentally go any further with what is available online. Please help me finish this code as much as possible.

``````leftxlim = 60
rightxlim = 130
mean = 95
SD = 2
#Two tailed test plotting
bt<-seq(leftxlim ,rightxlim,1)
plot(bt,dnorm(bt,mean,SD),type="l",main="Two tailed test", xlab = "", ylab = "")

abline(v=left.tail.xval)
abline(v=right.tail.xval)

cord.x<-c(leftxlim ,seq(leftxlim,left.tail.xval,1),left.tail.xval)
cord.y<-c(0,dnorm(seq(leftxlim ,left.tail.xval,1),mean,SD),0)
polygon(cord.x,cord.y,col="skyblue")

cord.x1<-c(right.tail.xval,seq(right.tail.xval,rightxlim,1),rightxlim)
cord.y1<-c(0,dnorm(seq(right.tail.xval,rightxlim,1),mean,SD),0)
polygon(cord.x1,cord.y1,col="skyblue")

cord.x2<-c(left.tail.xval,seq(left.tail.xval,right.tail.xval,1),right.tail.xval)
cord.y2<-c(0,dnorm(seq(left.tail.xval,right.tail.xval,1),mean,SD),0)
polygon(cord.x2,cord.y2,col="red")
``````

The only lack I see in your code, though I have not checked everything in detail, is the calculation of left.tail.xval and right.tail.xval. These can be calculated with the qnorm() function. For example

``````left.tail.xval <- qnorm(0.025, 95, 2)
``````

excellent i fugred that out but what respect will dnorm be used?

Thank you. I was able to resolve this. However is it possible to combine multiple data sets into one plot?

To produce two plots on the same image, all you have to do is change the plot function to a lines function when you draw the second distribution. Here is a rather long example.

``````leftxlim = 60
rightxlim = 130
mean = 95
SD = 2
#Two tailed test plotting
bt<-seq(leftxlim ,rightxlim,1)
plot(bt,dnorm(bt,mean,SD),type="l",main="Two tailed test", xlab = "", ylab = "")

left.tail.xval <- qnorm(0.025, mean, SD)
right.tail.xval <- qnorm(0.975, mean, SD)

abline(v=left.tail.xval)
abline(v=right.tail.xval)

cord.x<-c(leftxlim ,seq(leftxlim,left.tail.xval,1),left.tail.xval)
cord.y<-c(0,dnorm(seq(leftxlim ,left.tail.xval,1),mean,SD),0)
polygon(cord.x,cord.y,col="skyblue")

cord.x1<-c(right.tail.xval,seq(right.tail.xval,rightxlim,1),rightxlim)
cord.y1<-c(0,dnorm(seq(right.tail.xval,rightxlim,1),mean,SD),0)
polygon(cord.x1,cord.y1,col="skyblue")

cord.x2<-c(left.tail.xval,seq(left.tail.xval,right.tail.xval,1),right.tail.xval)
cord.y2<-c(0,dnorm(seq(left.tail.xval,right.tail.xval,1),mean,SD),0)
polygon(cord.x2,cord.y2,col="red")

leftxlim = 60
rightxlim = 130
mean = 85
SD = 2
#Two tailed test plotting
bt<-seq(leftxlim ,rightxlim,1)
lines(bt,dnorm(bt,mean,SD),type="l",main="Two tailed test", xlab = "", ylab = "")

left.tail.xval <- qnorm(0.025, mean, SD)
right.tail.xval <- qnorm(0.975, mean, SD)

abline(v=left.tail.xval)
abline(v=right.tail.xval)

cord.x<-c(leftxlim ,seq(leftxlim,left.tail.xval,1),left.tail.xval)
cord.y<-c(0,dnorm(seq(leftxlim ,left.tail.xval,1),mean,SD),0)
polygon(cord.x,cord.y,col="skyblue")

cord.x1<-c(right.tail.xval,seq(right.tail.xval,rightxlim,1),rightxlim)
cord.y1<-c(0,dnorm(seq(right.tail.xval,rightxlim,1),mean,SD),0)
polygon(cord.x1,cord.y1,col="skyblue")

cord.x2<-c(left.tail.xval,seq(left.tail.xval,right.tail.xval,1),right.tail.xval)
cord.y2<-c(0,dnorm(seq(left.tail.xval,right.tail.xval,1),mean,SD),0)
polygon(cord.x2,cord.y2,col="red")
``````

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.