Hi, I'm sure this should be fairly simple to do but I haven't found an example. I have 10 data points which are plotted as a line, I want to shade under this line with a colour. Other examples have shading under curves where there are two sets of data use polygons. mydata <- c(268,251,254,250,244,246,247,243,241,243) plot(mydata, type="o") polygon(c(ppp$total,length(ppp$total)), col="red") This gives me almost what I want but the line from the x-axis up to the first point on the line is squint. Could anyone suggest how to create my polygon so that it correctly shades underneath the line? Thanks, Alastair -- View this message in context: http://www.nabble.com/Shading-underneath-a-line-plot.-tp20153115p20153115.html Sent from the R help mailing list archive at Nabble.com.
Is this what you want: mydata <- c(268,251,254,250,244,246,247,243,241,243) plot(mydata, type="o") # choose a min y value minY <- 240 polygon(c(1, 1:10, 10), c(240, mydata, 240), col='red') On Fri, Oct 24, 2008 at 12:17 PM, Alastair Andrew <alastair.andrew at cis.strath.ac.uk> wrote:> > Hi, > > I'm sure this should be fairly simple to do but I haven't found an example. > I have 10 data points which are plotted as a line, I want to shade under > this line with a colour. Other examples have shading under curves where > there are two sets of data use polygons. > > mydata <- c(268,251,254,250,244,246,247,243,241,243) > plot(mydata, type="o") > polygon(c(ppp$total,length(ppp$total)), col="red") > > This gives me almost what I want but the line from the x-axis up to the > first point on the line is squint. Could anyone suggest how to create my > polygon so that it correctly shades underneath the line? > > Thanks, > Alastair > -- > View this message in context: http://www.nabble.com/Shading-underneath-a-line-plot.-tp20153115p20153115.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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 that you are trying to solve?
Is this what you want? mydata <- c(268,251,254,250,244,246,247,243,241,243) plot(mydata, type="o") polygon( c( 1, 1:length(mydata), length(mydata) ), c(0,mydata,0), col='red') I could not see your original plot since we don't know what ppp is. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at imail.org 801.408.8111> -----Original Message----- > From: r-help-bounces at r-project.org [mailto:r-help-bounces at r- > project.org] On Behalf Of Alastair Andrew > Sent: Friday, October 24, 2008 10:17 AM > To: r-help at r-project.org > Subject: [R] Shading underneath a line plot. > > > Hi, > > I'm sure this should be fairly simple to do but I haven't found an > example. > I have 10 data points which are plotted as a line, I want to shade > under > this line with a colour. Other examples have shading under curves where > there are two sets of data use polygons. > > mydata <- c(268,251,254,250,244,246,247,243,241,243) > plot(mydata, type="o") > polygon(c(ppp$total,length(ppp$total)), col="red") > > This gives me almost what I want but the line from the x-axis up to the > first point on the line is squint. Could anyone suggest how to create > my > polygon so that it correctly shades underneath the line? > > Thanks, > Alastair > -- > View this message in context: http://www.nabble.com/Shading-underneath- > a-line-plot.-tp20153115p20153115.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help at 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.