Re: [R] Groups in histograms?

From: Deepayan Sarkar <deepayan.sarkar_at_gmail.com>
Date: Fri 12 Aug 2005 - 23:55:46 EST

On 8/9/05, Fredrik Karlsson <dargosch@gmail.com> wrote:
> Dear list,
>
> Sorry for answering my own post, but I have had partial sucess in
> this. With the panel function below, I get separate histograms in each
> panel using the group argument.
>
> histogram(~vot | agem, nint=50,data=work,groups=Type, subset=agem > 24
> & agem < 30, panel=panel.grouphist,type="count",ylim=c(0,20),auto.key=T)
>
> panel.grouphist <- function(x,groups,...){
> add <- T
> grouplevels <- unique(groups)
> ngroups <- length(grouplevels)
>
> for(i in 1:ngroups){
> gcol <- trellis.par.get("superpose.fill")$col[i]
> gx <- x[groups == grouplevels[i]]
> panel.histogram(gx,col=gcol,...)
> }
>
> }
>
> However, the color I get in the key using simpleKey is not the same as
> the one in the the plot.
> How do I get the two functions to use the same color scale?

How are you using simpleKey? I get the same colors by adding

histogram(...

                 auto.key = list(points = FALSE, rectangles = TRUE))

By the way, have you considered using a grouped 'densityplot' instead?

Deepayan



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 Received on Sat Aug 13 00:00:34 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:16:28 EST