On 4/17/07, yannig goude <[EMAIL PROTECTED]> wrote:
>  I want to add different colors on the background of a classical plot. Each 
> color is associated to an interval of the x axis.
>  example: the background is red on the interval [1,10], blue on [11,20].
>  I try the rect function but it isn't appropriate for the background..

You can use rect together with par("usr") like this:

usr <- par("usr")
plot(1:20, type = "n")
rect(1, usr[3], 10, usr[4], col = "red")
rect(11, usr[3], 20, usr[4], col = "blue")
points(1:20)

There is also an example of this using polygon in place of rect here:

http://www.mayin.org/ajayshah/KB/R/html/g5.html

and an example of doing it with lattice graphics using xyplot.zoo
(the same idea would work with xyplot) mid way through the examples in:

library(zoo)
?xyplot.zoo

______________________________________________
[email protected] 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.

Reply via email to