[R] background color

Petr Klasterecky klaster at karlin.mff.cuni.cz
Tue Apr 17 10:54:09 CEST 2007


What do you mean by background? Maybe this is enough:

plot(seq(-3,3,.01), dnorm(seq(-3,3,.01)), type="n", xlab="x", 
ylab="f(x)", main="Normal density")
polygon(x=c(-4,0,0,-4), y=c(-1,-1,.5,.5), col="red")
polygon(x=c(4,0,0,4), y=c(-1,-1,.5,.5), col="blue")
lines(seq(-3,3,.01), dnorm(seq(-3,3,.01)), type="l", lwd=2)

Play a little bit with the polygon margins to get what you need. You can 
even generate them automatically based on your data.

Petr

yannig goude napsal(a):
> hi,
>   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.
>   Can any one can help me please?
>   best regards.
>      
> 
>              
> ---------------------------------
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
> 

-- 
Petr Klasterecky
Dept. of Probability and Statistics
Charles University in Prague
Czech Republic



More information about the R-help mailing list