Re: [R] coloring a graph left or right of an abline

From: Roland Rau <roland.rproject_at_gmail.com>
Date: Thu, 21 Feb 2008 15:21:39 -0500

Hi Georg,

Georg Ehret wrote:
> Dear R community,
> I would wish to color the background of my histogram differently to the
> left and right of an abline... Can you please help?

maybe not very elegant or beautiful, but I hope it will get you started:

################### Start of Code Example
n <- 1000
myxlims <- c(-3,3)
myylims <- c(0,0.6)
mydata <- rnorm(n)
marker <- 1
hist(mydata, breaks=50, xlim=myxlims, ylim=myylims, freq=FALSE) rect(xleft=myxlims[1], xright=marker, ybottom=0, ytop=max(myylims),

      col="red", border=FALSE)
rect(xleft=marker, xright=myxlims[2], ybottom=0, ytop=max(myylims),

      col="blue", border=FALSE)
hist(mydata, breaks=50, xlim=myxlims, ylim=myylims, col="green",

      freq=FALSE, add=TRUE)
abline(v=marker, col="black", lwd=3, lty=1)

################### End of Code Example

Best,
Roland

>
> Thankin you,
> Georg.
>
> ****************************
> Georg Ehret
> JHU
> Baltimore - USA
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> 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.
>



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. Received on Thu 21 Feb 2008 - 20:26:28 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 21 Feb 2008 - 20:30:17 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive