# Polygon

10 messages
Open this post in threaded view
|

## Polygon

 Can someone help me with polygon. The following codes are self-runnable and mark a shaded area under the standard normal curve in the x-range (-3,-1). Is there a way to also mark the area in (1,3), at the same time. That is, I want shaded areas in both tails. Thank you... === # Create data for the area to shade cord.x <- c(-3,seq(-3,-1,0.01),-1) cord.y <- c(0,dnorm(seq(-3,-1,0.01)),0) # Make a curve curve(dnorm(x,0,1), xlim=c(-3,3), main='Standard Normal') # Add the shaded area. polygon(cord.x,cord.y,col='skyblue') -- [hidden email] (S.T. Yen)         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Polygon

 Hello, Continue with polygon(-rev(cord.x), rev(cord.y), col = 'skyblue') Hope this helps, Rui Barradas Às 17:25 de 02/10/2018, Steven Yen escreveu: > Can someone help me with polygon. The following codes are self-runnable > and mark a shaded area under the standard normal curve in the x-range > (-3,-1). > Is there a way to also mark the area in (1,3), at the same time. > That is, I want shaded areas in both tails. Thank you... > > === > # Create data for the area to shade > cord.x <- c(-3,seq(-3,-1,0.01),-1) > cord.y <- c(0,dnorm(seq(-3,-1,0.01)),0) > > # Make a curve > curve(dnorm(x,0,1), xlim=c(-3,3), main='Standard Normal') > > # Add the shaded area. > polygon(cord.x,cord.y,col='skyblue') > ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Polygon

 Great. Thanks! It did wonders. 1. Is there a way to suppress the obvious tick stops (-3,-2,-1,0,1,2,3) and mark only the ticks -1.96 and 1.96. 2. Better yet, to draw vertical lines at x = -1.96 and x = 1.96. Thanks. Steven On 10/3/2018 12:51 AM, Rui Barradas wrote: > Hello, > > Continue with > > > polygon(-rev(cord.x), rev(cord.y), col = 'skyblue') > > > Hope this helps, > > Rui Barradas > > Às 17:25 de 02/10/2018, Steven Yen escreveu: >> Can someone help me with polygon. The following codes are self-runnable >> and mark a shaded area under the standard normal curve in the x-range >> (-3,-1). >> Is there a way to also mark the area in (1,3), at the same time. >> That is, I want shaded areas in both tails. Thank you... >> >> === >> # Create data for the area to shade >> cord.x <- c(-3,seq(-3,-1,0.01),-1) >> cord.y <- c(0,dnorm(seq(-3,-1,0.01)),0) >> >> # Make a curve >> curve(dnorm(x,0,1), xlim=c(-3,3), main='Standard Normal') >> >> # Add the shaded area. >> polygon(cord.x,cord.y,col='skyblue') >> > -- [hidden email] (S.T. Yen)         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Polygon

Open this post in threaded view
|

## Re: Polygon

Open this post in threaded view
|

## Re: Polygon

Open this post in threaded view
|

## Re: Polygon

 In reply to this post by David Winsemius David, Rui, and All: Greetings. 1. I need a helping hand with the polygon statement below so that I can have the area under the curve highlighted, between (z1,z2). 2. Is it possible to label the X-axis with in two scale, in the current z-scale and another, say x = (z+5)*2? Thank you. z1<- -1 z2<-  2 curve(dnorm(x,0,1),xlim=c(-4,4),main="Standard Normal",xaxt="n",frame=F,xlab="z") jj<-seq(z1,z2,0.01) cord.x<-c(jj) cord.y<-c(dnorm(jj)) #polygon(cord.x,cord.y,col="skyblue") axis(1,at=c(-5,z1,0,z2,5),lab=c(-5,z1,0,z2,5)) abline(v=c(z1,z2)) -- [hidden email] (S.T. Yen)         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: Polygon

 I think this does what you want. z1<- -1 z2<-  2 oldp <- par(mgp=c(3, .5, 0)) curve(dnorm(x,0,1), xlim=c(-5, 5),main="Standard Normal",     xaxt="n", frame=F, xlab="") jj<-seq(z1,z2,0.01) cord.x<- jj cord.y<- dnorm(jj) polygon(c(-1, cord.x, 2), c(0, cord.y, 0), col="skyblue") axis(1,at=c(-5,z1,0,z2,5),lab=c(-5,z1,0,z2,5)) abline(v=c(z1,z2)) axis(1, at=c(-5, z1, 0, z2, 5), lab=(c(-5,z1,0,z2,5) + 5)*2, line=2) par(oldp) When you assign a vector to an object, you do not need to use c(), e.g. cord.x <- jj. I expanded xlim= since you were labeling the axis at -5, and 5, but only drawing the plot from -4 to 4. To get the polygon to work, you need to add points to the baseline at at either end. The line= argument in axis() lets you put an axis line into the margin of the plot. I used the mgp= argument in par() to close the space between the tickmarks and their values. -------------------------------------- David L. Carlson Department of Anthropology Texas A&M University -----Original Message----- From: R-help [mailto:[hidden email]] On Behalf Of Steven Yen Sent: Sunday, October 21, 2018 1:47 PM To: David Winsemius <[hidden email]> Cc: [hidden email] Subject: Re: [R] Polygon David, Rui, and All: Greetings. 1. I need a helping hand with the polygon statement below so that I can have the area under the curve highlighted, between (z1,z2). 2. Is it possible to label the X-axis with in two scale, in the current z-scale and another, say x = (z+5)*2? Thank you. z1<- -1 z2<-  2 curve(dnorm(x,0,1),xlim=c(-4,4),main="Standard Normal",xaxt="n",frame=F,xlab="z") jj<-seq(z1,z2,0.01) cord.x<-c(jj) cord.y<-c(dnorm(jj)) #polygon(cord.x,cord.y,col="skyblue") axis(1,at=c(-5,z1,0,z2,5),lab=c(-5,z1,0,z2,5)) abline(v=c(z1,z2)) -- [hidden email] (S.T. Yen)         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code. ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.