Re: [R] Shaded area
Hi all, I was quite intrigued by George's question, for I thought this might be a problem faced by many. The solution attached is only useful for a monotonically increasing x vector, a paired vector of y values, and a criterial value above which a polygon will be displayed. More work would needed for curves that are above the criterial value at the beginning or end, and a corresponding argument to fill the area _below_ the criterial value. If it is useful, I can probably do a bit more work on it. Jim On Fri, Mar 3, 2023 at 11:58 PM John Kane wrote: > > As Peter says, the list is very cautious about what types of files it > allows. A handy way to supply some sample data is the dput() function. In > the case of a large dataset something like dput(head(mydata, 100)) should > supply the data we need. Just do dput(mydata) where *mydata* is your data. > Copy the output and paste it here. > > On Wed, 1 Mar 2023 at 09:58, PIKAL Petr wrote: > > > Hallo > > > > Excel attachment is not allowed here, but shading area is answered many > > times elsewhere. Use something like . "shading area r" in google. > > > > See eg. > > https://www.geeksforgeeks.org/how-to-shade-a-graph-in-r/ > > > > Cheers Petr > > > > -Original Message- > > From: R-help On Behalf Of George Brida > > Sent: Wednesday, March 1, 2023 3:21 PM > > To: r-help@r-project.org > > Subject: [R] Shaded area > > > > Dear R users, > > > > I have an xlsx file (attached to this mail) that shows the values of a > > "der" series observed on a daily basis from January 1, 2017 to January 25, > > 2017. This series is strictly positive during two periods: from January 8, > > 2017 to January 11, 2017 and from January 16, 2017 to January 20, 2017. I > > would like to plot the series with two shaded areas corresponding to the > > positivity of the series. Specifically, I would like to draw 4 vertical > > lines intersecting the x-axis in the 4 dates mentioned above and shade the > > two areas of positivity. Thanks for your help. > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních > > partnerů PRECHEZA a.s. jsou zveřejněny na: > > https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information > > about processing and protection of business partner’s personal data are > > available on website: > > https://www.precheza.cz/en/personal-data-protection-principles/ > > Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou > > důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení > > odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any > > documents attached to it may be confidential and are subject to the legally > > binding disclaimer: https://www.precheza.cz/en/01-disclaimer/ > > > > __ > > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide > > http://www.R-project.org/posting-guide.html > > and provide commented, minimal, self-contained, reproducible code. > > > > > -- > John Kane > Kingston ON Canada > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Shaded area
As Peter says, the list is very cautious about what types of files it allows. A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need. Just do dput(mydata) where *mydata* is your data. Copy the output and paste it here. On Wed, 1 Mar 2023 at 09:58, PIKAL Petr wrote: > Hallo > > Excel attachment is not allowed here, but shading area is answered many > times elsewhere. Use something like . "shading area r" in google. > > See eg. > https://www.geeksforgeeks.org/how-to-shade-a-graph-in-r/ > > Cheers Petr > > -Original Message- > From: R-help On Behalf Of George Brida > Sent: Wednesday, March 1, 2023 3:21 PM > To: r-help@r-project.org > Subject: [R] Shaded area > > Dear R users, > > I have an xlsx file (attached to this mail) that shows the values of a > "der" series observed on a daily basis from January 1, 2017 to January 25, > 2017. This series is strictly positive during two periods: from January 8, > 2017 to January 11, 2017 and from January 16, 2017 to January 20, 2017. I > would like to plot the series with two shaded areas corresponding to the > positivity of the series. Specifically, I would like to draw 4 vertical > lines intersecting the x-axis in the 4 dates mentioned above and shade the > two areas of positivity. Thanks for your help. > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních > partnerů PRECHEZA a.s. jsou zveřejněny na: > https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information > about processing and protection of business partner’s personal data are > available on website: > https://www.precheza.cz/en/personal-data-protection-principles/ > Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou > důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení > odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any > documents attached to it may be confidential and are subject to the legally > binding disclaimer: https://www.precheza.cz/en/01-disclaimer/ > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- John Kane Kingston ON Canada [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] Shaded area
Hallo Excel attachment is not allowed here, but shading area is answered many times elsewhere. Use something like . "shading area r" in google. See eg. https://www.geeksforgeeks.org/how-to-shade-a-graph-in-r/ Cheers Petr -Original Message- From: R-help On Behalf Of George Brida Sent: Wednesday, March 1, 2023 3:21 PM To: r-help@r-project.org Subject: [R] Shaded area Dear R users, I have an xlsx file (attached to this mail) that shows the values of a "der" series observed on a daily basis from January 1, 2017 to January 25, 2017. This series is strictly positive during two periods: from January 8, 2017 to January 11, 2017 and from January 16, 2017 to January 20, 2017. I would like to plot the series with two shaded areas corresponding to the positivity of the series. Specifically, I would like to draw 4 vertical lines intersecting the x-axis in the 4 dates mentioned above and shade the two areas of positivity. Thanks for your help. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Osobní údaje: Informace o zpracování a ochraně osobních údajů obchodních partnerů PRECHEZA a.s. jsou zveřejněny na: https://www.precheza.cz/zasady-ochrany-osobnich-udaju/ | Information about processing and protection of business partner’s personal data are available on website: https://www.precheza.cz/en/personal-data-protection-principles/ Důvěrnost: Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a podléhají tomuto právně závaznému prohláąení o vyloučení odpovědnosti: https://www.precheza.cz/01-dovetek/ | This email and any documents attached to it may be confidential and are subject to the legally binding disclaimer: https://www.precheza.cz/en/01-disclaimer/ __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] Shaded area
Dear R users, I have an xlsx file (attached to this mail) that shows the values of a "der" series observed on a daily basis from January 1, 2017 to January 25, 2017. This series is strictly positive during two periods: from January 8, 2017 to January 11, 2017 and from January 16, 2017 to January 20, 2017. I would like to plot the series with two shaded areas corresponding to the positivity of the series. Specifically, I would like to draw 4 vertical lines intersecting the x-axis in the 4 dates mentioned above and shade the two areas of positivity. Thanks for your help. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] shaded area between a curve and a circle
The figure is not ok. The coordinate of the normal curve is not the same as that of the circle. In fact, there are only four intersections other than eight that your figure show. Best, Jinsong On 2022/10/23 3:05, L... L... wrote: Dear, I have a picture in which I draw a circle over the standard normal curve. See below the lines used to draw the figure. The figure is ok, but my problem is: How to shade the areas A, B, C, D, E and F? I know I have to find the points of intersection but I don't know how to find them. Suggestions will be welcome. library(plotrix) x <- seq(-3.0, 3.0, 0.01) fy <- dnorm(x) fy <- fy / max(fy) x11() plot(x, fy, ylim = c(-1, 1), col = "white", lwd = 1.5, xlim = c(-3, 3), lty = 1) draw.circle(0.0, 0.0, 2.00, border = 'blue', lty = 1, lwd = 0.8) lines(x, fy, type = 'l', ylim = c(-1,1), col = 'red', ) lines(x,-fy, type = 'l', ylim = c(-1,1), col = 'red') text( 0.0, 0.90, "A"); text( 0.0,-0.90, "B") text(-1.8, 0.25, "C"); text( 1.8, 0.25, "D") text(-1.8,-0.25, "E"); text( 1.8,-0.25, "F") Best regards ML [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] shaded area between a curve and a circle
The points on your density curve can be written as (x, f(x)) - well, if you had not divided by its max value which I do not understand why. Now you simply need to find out which of these points have a distance of the circle's radius to the point (0,0). Hmmm, your "circle" has a radius of 2 in x direction but less in y direction? So this is not a circle but an ellipse given the coordinate system used? Assuming you actually want to draw a circle of radius r, then I would simply solve Pythagoras' equation, i.e. sqrt(x^2 + f(x)^2) == r e.g. via uniroot(). But first you need to find out what you actually want to do. Best, Uwe Ligges On 22.10.2022 21:05, L... L... wrote: Dear, I have a picture in which I draw a circle over the standard normal curve. See below the lines used to draw the figure. The figure is ok, but my problem is: How to shade the areas A, B, C, D, E and F? I know I have to find the points of intersection but I don't know how to find them. Suggestions will be welcome. library(plotrix) x <- seq(-3.0, 3.0, 0.01) fy <- dnorm(x) fy <- fy / max(fy) x11() plot(x, fy, ylim = c(-1, 1), col = "white", lwd = 1.5, xlim = c(-3, 3), lty = 1) draw.circle(0.0, 0.0, 2.00, border = 'blue', lty = 1, lwd = 0.8) lines(x, fy, type = 'l', ylim = c(-1,1), col = 'red', ) lines(x,-fy, type = 'l', ylim = c(-1,1), col = 'red') text( 0.0, 0.90, "A"); text( 0.0,-0.90, "B") text(-1.8, 0.25, "C"); text( 1.8, 0.25, "D") text(-1.8,-0.25, "E"); text( 1.8,-0.25, "F") Best regards ML [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] shaded area between a curve and a circle
Dear, I have a picture in which I draw a circle over the standard normal curve. See below the lines used to draw the figure. The figure is ok, but my problem is: How to shade the areas A, B, C, D, E and F? I know I have to find the points of intersection but I don't know how to find them. Suggestions will be welcome. library(plotrix) x <- seq(-3.0, 3.0, 0.01) fy <- dnorm(x) fy <- fy / max(fy) x11() plot(x, fy, ylim = c(-1, 1), col = "white", lwd = 1.5, xlim = c(-3, 3), lty = 1) draw.circle(0.0, 0.0, 2.00, border = 'blue', lty = 1, lwd = 0.8) lines(x, fy, type = 'l', ylim = c(-1,1), col = 'red', ) lines(x,-fy, type = 'l', ylim = c(-1,1), col = 'red') text( 0.0, 0.90, "A"); text( 0.0,-0.90, "B") text(-1.8, 0.25, "C"); text( 1.8, 0.25, "D") text(-1.8,-0.25, "E"); text( 1.8,-0.25, "F") Best regards ML [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] shaded area with polygon
Does polygon(c(x,rev(x)), c(y, rev(z)), col="orange") do what you want? Bill Dunlap TIBCO Software wdunlap tibco.com On Mon, Jun 11, 2018 at 12:35 PM, L... L... wrote: > Dear All, I know this is a trivial question .. but .. I want to shade the > area between 2 curves. For example: > > x <- 1:10 > > y <- 3*x^2 + 2*x + 7 > > z <- y + 100 > > plot(x, y, type = 'l') > > lines(x, z) > > I can not understand polygon. > > I tried > > polygon(cbind(c(min(x), x, max(x)), c(min(y), z, max(y))), col="#00CC66") > > But I do not return what I want. > > Thank you very much > > ML > > > > [[alternative HTML version deleted]] > > __ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/ > posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] __ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] shaded area graph and extra plot
R-help, I'm using the code below to plot a shaded area graph. At the same time I want to plot a second series on the y-axis (from par(new=T) on) but as the two series have different x-axis range (first 1994:2007 and second 1996:2007) the corresponding x's do not match. How can this be sorted out? Thanks in advance # plot.new() plot.window(xlim=c(1993,2008), xaxs="i", ylim=c(0,400), yaxs="i") x=1994:2007 xx = c(1994, x, 2007) yy1 = c(0, indexSp[,"Xhat5Sp"]+indexSp[,"seA"], 0 ) yy2 = c(0, indexSp[,"Xhat5Sp"]-indexSp[,"seA"], 0 ) polygon(xx, yy1, col="grey", lty=0) polygon(xx, yy2, col="white", lty=0) lines(x, indexSp[,"Xhat5Sp"], type="l") axis(1) axis(2) par(new=T) plot(1996:2007, c(0,0,indexSu[,"Xhat5Su"]), type="p", col=2, lwd=2, cex=1,ann=T,axes=F) axis(4) # __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Re: [R] shaded area graph and extra plot
Use 'xlim=c(1993,2008)' in your second plot to setup the same range. On Feb 12, 2008 10:39 AM, Luis Ridao Cruz <[EMAIL PROTECTED]> wrote: > R-help, > > I'm using the code below to plot a shaded area graph. > > At the same time I want to plot a second series on the y-axis (from > par(new=T) on) > but as the two series have different x-axis range (first 1994:2007 and > second 1996:2007) > the corresponding x's do not match. > > How can this be sorted out? > > Thanks in advance > > # > plot.new() > plot.window(xlim=c(1993,2008), xaxs="i", ylim=c(0,400), yaxs="i") > > x=1994:2007 > xx = c(1994, x, 2007) > > yy1 = c(0, indexSp[,"Xhat5Sp"]+indexSp[,"seA"], 0 ) > yy2 = c(0, indexSp[,"Xhat5Sp"]-indexSp[,"seA"], 0 ) > > polygon(xx, yy1, col="grey", lty=0) > polygon(xx, yy2, col="white", lty=0) > lines(x, indexSp[,"Xhat5Sp"], type="l") > > axis(1) > axis(2) > > par(new=T) > plot(1996:2007, c(0,0,indexSu[,"Xhat5Su"]), type="p", col=2, lwd=2, > cex=1,ann=T,axes=F) > axis(4) > # > > __ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > -- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem you are trying to solve? __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
[R] shaded area graph and extra plot
R-help, I'm using the code below to plot a shaded area graph. At the same time I want to plot a second series on the y-axis (from par(new=T) on) but as the two series have different x-axis range (first 1994:2007 and second 1996:2007) the corresponding x's do not match. How can this be sorted out? Thanks in advance # plot.new() plot.window(xlim=c(1993,2008), xaxs="i", ylim=c(0,400), yaxs="i") x=1994:2007 xx = c(1994, x, 2007) yy1 = c(0, indexSp[,"Xhat5Sp"]+indexSp[,"seA"], 0 ) yy2 = c(0, indexSp[,"Xhat5Sp"]-indexSp[,"seA"], 0 ) polygon(xx, yy1, col="grey", lty=0) polygon(xx, yy2, col="white", lty=0) lines(x, indexSp[,"Xhat5Sp"], type="l") axis(1) axis(2) par(new=T) plot(1996:2007, c(0,0,indexSu[,"Xhat5Su"]), type="p", col=2, lwd=2, cex=1,ann=T,axes=F) axis(4) # __ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.