[R] Histogram with lattice with two 'conditional' variables
Deepayan Sarkar
deepayan.sarkar at gmail.com
Fri Apr 3 00:24:00 CEST 2009
On Thu, Apr 2, 2009 at 3:16 PM, Judith Flores <juryef at yahoo.com> wrote:
>
> Hello dear R-community,
>
> I have been trying to figure out a way to generate histograms of a numeric variable observed in different entities ('individual' below). Each one of this entities is classified as "A" or "B" (according to the pseudo-code below):
>
>
> variable<-sample(rep(1:10,10))
> individual<-rep(1:10, length(variable))
> group<-rep(LETTERS[1:2],length(variable)/2)
>
> mydata<-data.frame(variable,individual,group)
>
> library('lattice')
>
> attach(mydata)
> individual<-as.factor(individual)
> group<-as.factor(group)
> histogram(~variable|individual+group)
>
> If you run the above code you will obtain a series of panels that correspond to every entity, but replicated, which makes sense because I am telling it to generate histograms by entity and by group, but the reality is that each entity only belongs to one of the groups, but then some plots appear empty, as they should. That means that only the plots that have data in it are 'real'.
>
> My question is: how can I generate a layout where only the 'real' data exists and still get the two strips that specify the individual and group?
histogram(~variable| interaction(individual, group))
-Deepayan
More information about the R-help
mailing list