[R] curves with shaded areas?

Christophe Declercq cdeclercq at nordnet.fr
Tue Jul 22 14:06:38 CEST 2003


> 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




More information about the R-help mailing list