Re: [R] Groups in histograms?

From: Fredrik Karlsson <dargosch_at_gmail.com>
Date: Tue 09 Aug 2005 - 18:29:36 EST

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?

/Fredrik

On 8/8/05, Fredrik Karlsson <dargosch@gmail.com> wrote:
> Hi Gary,
>
> I have found this, but it is not exactly what I am looking for.
> What I need is the groups to be inside of a single panel, not in
> different panels.
> Kind of like an histogram version of the xyplot(Y ~ X1,
> groups=X2,panel=panel.superpose) command. (I hope this is correct).
>
> /Fredrik
>
> On 8/8/05, Gary Collins <collins.gs@gmail.com> wrote:
> > Have a look at the "histogram" function in the Lattice package.
> >
> > if x are your data to be displayed and y is your grouping variable you
> > can just do
> >
> > > histogram(~x|y)
> >
> > HTH
> > Gary
> >
> > On 08/08/05, Fredrik Karlsson <dargosch@gmail.com> wrote:
> > > Dear list,
> > >
> > > I would like to create histograms for up to three groups, with
> > > distincive colour/pattern, in a trellis panel. However, I have not
> > > been able to find a way to do this. histogram does not seem to have a
> > > group argument.
> > >
> > > Please help.
> > >
> > > /Fredrik
> > >
> > > ______________________________________________
> > > 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
> > >
> >



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 Tue Aug 09 18:34:12 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:39:45 EST