I will attempt to distill my problem down to a simpler one, the solution of which will hopefully lead me to the nirvana of complete understanding, i.e., inserting a polygon beneath an irregular line terminated by the x axis.
I 'know' that polygon will work -provided- I knew the xy coordinates of the line(s) beneath which I desire to create the polygon. Unfortunately, I don't know how to get at that info. Below is an example of a irregular line for which the xy coordinates are not known (i.e., at least not by me). I assume my problem boils down to finding out how to extract the xy from that line. attach(cars) plot(dist ~ speed) scatter.smooth(speed, dist,family = "gaussian",span = .2) Gregory A. Graves Lead Scientist Everglades REstoration COoordination and VERification (RECOVER) Watershed Division South Florida Water Management District Phones: DESK: 561 / 682 - 2429 CELL: 561 / 719 - 8157 From: Debabrata Midya [mailto:debabrata.mi...@commerce.nsw.gov.au] Sent: Thursday, August 13, 2009 6:36 PM To: Graves, Gregory Cc: r-help@r-project.org Subject: Re: [R] shading between two smoothed curves Hi Gregory, > I can plot out two nice curves using the following code, but I can't figure out how to shade in the area lying between the two curves. Use polygon. > ?polygon >>> "Graves, Gregory" <ggra...@sfwmd.gov> 14/08/2009 4:17 am >>> I have a set of 52 weekly values, one is the desired high lake stage for a week, and the other is the desired low lake stage for each week. It looks like this: week High Low 1 16 14.5 2 16 14.5 3 15.95 14.45 4 15.84 14.34 5 15.73 14.23 6 15.61 14.11 7 15.5 14 8 15.38 13.88 9 15.25 13.75 10 15.13 13.63 .... 52 15 13.5 I can plot out two nice curves using the following code, but I can't figure out how to shade in the area lying between the two curves. I also can't figure out how to adjust the line weight as lwd doesn't seem to affect scatter.smooth. Thanks in advance. l=11 #lower ylim h=17 #upper ylim par(new=F) good <- complete.cases(week, high) #get rid of the NA error and only using non-missing pairs par(new=T) scatter.smooth(week[good], high[good],family = "gaussian",span = .2, ylim=c(l,h), type='n', lwd=2, color="blue", ylab="", xlab="") good <- complete.cases(week, low) par(new=T) scatter.smooth(week[good], low[good],family = "gaussian",span = .2, ylim=c(l,h), type='n', lwd=2, color="red", ylab="Stage, feet", xlab="Week of Year") #loess, lower span makes more irregular par(new=F) Gregory A. Graves Lead Scientist Everglades REstoration COoordination and VERification (RECOVER) Watershed Division South Florida Water Management District Phones: DESK: 561 / 682 - 2429 CELL: 561 / 719 - 8157 [[alternative HTML version deleted]] ______________________________________________ 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. ****************************************************************************** This email message, including any attached files, is confidential and intended solely for the use of the individual or entity to whom it is addressed. The NSW Department of Commerce prohibits the right to publish, copy, distribute or disclose any information contained in this email, or its attachments, by any party other than the intended recipient. If you have received this email in error please notify the sender and delete it from your system. No employee or agent is authorised to conclude any binding agreement on behalf of the NSW Department of Commerce by email. The views or opinions presented in this email are solely those of the author and do not necessarily represent those of the Department, except where the sender expressly, and with authority, states them to be the views of NSW Department of Commerce. The NSW Department of Commerce accepts no liability for any loss or damage arising from the use of this email and recommends that the recipient check this email and any attached files for the presence of viruses. ****************************************************************************** ______________________________________________ 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.