[R] Histogram with lattice with two 'conditional' variables

Judith Flores juryef at yahoo.com
Fri Apr 3 00:16:33 CEST 2009


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?

Thank you very much in advance for any help you can provide me with,

Judith




More information about the R-help mailing list