On 9/15/06, Benjamin Tyner <btyner at gmail.com>
wrote:> In dotplot, what's the best way to suppress the unused levels of
'y' on
> a per-panel basis? This is useful for the case that 'y' is a factor
> taking perhaps thousands of levels, but for a given panel, only a
> handfull of these levels ever present.
It's a bit problematic. Basically, you can use
relation="free"/"sliced", but y behaves as as.numeric(y)
would. So, if
the small subset in each panel are always more or less contiguous (in
terms of the levels being close to each other) then you would be fine.
Otherwise you would not. In that case, you can still write your own
prepanel and panel functions, e.g.:
-------------
library(lattice)
y <- factor(sample(1:100), levels = 1:100)
x <- 1:100
a <- gl(9, 1, 100)
dotplot(y ~ x | a)
p <-
dotplot(y ~ x | a,
scales = list(y = list(relation = "free", rot = 0)),
prepanel = function(x, y, ...) {
yy <- y[, drop = TRUE]
list(ylim = levels(yy),
yat = sort(unique(as.numeric(yy))))
},
panel = function(x, y, ...) {
yy <- y[, drop = TRUE]
panel.dotplot(x, yy, ...)
})
----------
Hope that gives you what you want.
Deepayan