Re: [R] histogram colors in lattice

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Wed 27 Sep 2006 - 03:58:43 GMT

Try this:

library(lattice)
set.seed(1) ## added for reproducibility Start <- factor(rbinom(100,1,.5))
Answer <- 2 - rbinom(100,1,.7)

histogram(~Answer | Start,

         breaks=c(1, 1.4 ,1.6,2),
         scales=list(x=list(at=c(1.2,1.8),labels=c("Yes","No"))),
         panel = function(x, ..., panel.number, col) {  ## added this
panel function
              panel.histogram(x, ..., col = panel.number+1)
          },
         xlab="",ylab="")


On 9/26/06, Jamie Jarabek <jamie.jarabek@gmail.com> wrote:
> I have code that constructs a plot using the lattice package that looks
> something like the following toy example:
>
> library(lattice)
> Start <- factor(rbinom(100,1,.5))
> Answer <- 2 - rbinom(100,1,.7)
>
> histogram(~Answer | Start,
> breaks=c(1, 1.4 ,1.6,2),
> scales=list(x=list(at=c(1.2,1.8),labels=c("Yes","No"))),
> xlab="",ylab="")
>
> I would like to have different colors for the bars in the left and right
> panel (say red and green) but I can't find a way to do this. Can anyone give
> me any advice on how to achieve this?
>
> Thanks,
> Jamie Jarabek
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>



R-help@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. Received on Wed Sep 27 14:02:14 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 27 Sep 2006 - 06:30:06 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.