Hi, I want to make a plot with abline where the area below or above the curve is shaded. I can't find any documentation on that. Can anybody help me with that? thanks, Juffi
See ?polygon, ?rect for how to shade areas. If you make a plot with abline, surely it has no curves (only straight lines)? On Tue, 22 Jul 2003, Johannes Fuernkranz wrote:> I want to make a plot with abline where the area below or above the > curve is shaded. I can't find any documentation on that. Can anybody > help me with that?-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
polygon() together with par("usr") would be your friend here. As I do not know if you want horisontal/vertical lines or any line, here is a general example: # Generate the data x <- seq(from=1, to=3.5*pi, length=100) y <- sin(x) # Creates an empty plot of right size plot(x,y, type="n") # Get plotting region x0 <- par("usr")[1]; x1 <- par("usr")[2]; y0 <- par("usr")[3]; y1 <- par("usr")[4]; last <- length(y) # Create the "upper" polygon polygon(c(x0,x0,x,x1,x1), c(y1,y[1],y,y[last],y1), col="#ffcccc", border=NA) # Create the "lower" polygon polygon(c(x0,x0,x,x1,x1), c(y0,y[1],y,y[last],y0), col="#ccccff", border=NA) # Plot the data on top points(x,y) As you see, as there are 4% margins by default, you have to specify what you want to do at the margins. Depending on if you want regions defined by abline(h)/abline(v) or by abline(a,b) you solution will be somewhat different. Cheers Henrik Bengtsson Lund University> -----Original Message----- > From: r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of > Johannes Fuernkranz > Sent: den 22 juli 2003 12:10 > To: r-help at stat.math.ethz.ch > Subject: [R] curves with shaded areas? > > > Hi, > > I want to make a plot with abline where the area below or above the > curve is shaded. I can't find any documentation on that. Can anybody > help me with that? > > thanks, Juffi > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://www.stat.math.ethz.ch/mailman/listinfo> /r-help > > >
> De : r-help-bounces at stat.math.ethz.ch > [mailto:r-help-bounces at stat.math.ethz.ch]De la part de Johannes > Fuernkranz[...]> I want to make a plot with abline where the area below or above the > curve is shaded. I can't find any documentation on that. Can anybody > help me with that?[...] You have to play with par("usr"). See the toy example below, perhaps a little naive, but it seems to do what you want. ## tmp<-rnorm(100) mydf<-data.frame(x=tmp, y=0.5*tmp+rnorm(100)) plot(y~x, mydf) myreg<-lm(y~x, mydf) abline(myreg) x1<-par("usr")[1:2] y1<-par("usr")[3] myxy<-rbind( cbind(x1, predict(myreg, data.frame(x=x1))), cbind(rev(x1), rep(y1,2)) ) polygon(myxy, col="grey") ## I hope it helps. Christophe -- Christophe DECLERCQ, MD Observatoire R?gional de la Sant? Nord-Pas-de-Calais 13, rue Faidherbe 59046 LILLE Cedex FRANCE Phone +33 3 20 15 49 24 Fax +33 3 20 55 92 30 E-mail c.declercq at orsnpdc.org
Apparently Analagous Threads
- data structure with coefficients, and call from lm()
- Plotting shaded areas
- [LLVMdev] Passing specific register for an Instruction in target description files.
- using vif from package "car" - "aliased coefficients in the model"
- store list objects in data.table