[R] Dotplot with nested factors

Raubertas, Richard richard_raubertas at merck.com
Tue Aug 17 00:06:18 CEST 2004


I am using the dotplot function from the lattice package to
display a quantitative variable versus two factors, say 'a' and
'b'.  The levels of 'a' are nested within levels of 'b'.  The 
issue is that dotplot includes all the levels of 'a' in each panel
(conditioning on 'b'), even though many are empty in any given 
panel.  A toy example is

dat <- data.frame(a=letters[1:5], b=c("A","A","A","B","B"), y=1:5)
dotplot(y ~ a | b, data=dat)

(In the real data, there are far more levels of 'a' and 'b', so each
panel ends up with all its data squashed into a small portion of 
the available space.)

I would like to show only the levels of 'a' actually present 
in a given panel.  I hoped that setting 'relation="free"' would 
cause each panel to adjust its axis to match the set of 'a' values 
observed in that panel, but unfortunately it seems 'relation' is 
ignored for factors.  Would it make sense to have 'relation' work
for factors?  Is there some other way to accomplish the same effect?

Rich Raubertas
Merck & Co.




More information about the R-help mailing list