Skip to content
Prev 12064 / 63424 Next

lattice/grid: problem with viewports for strips with zero height

On Wednesday 03 March 2004 04:08, Wolfram Fischer wrote:
Looks like a grid bug/feature where non-zero 'y' in grid.text doesn't work 
for viewports with zero height, even if clipping is turned off. Simpler 
example:

grid.text("some text", y = unit(6, "points"), 
          just = c("center", "bottom"), 
          vp = viewport(x = .5, y = .5, h = 0, clip = FALSE))
                                        ^^^^^

(Works if h > 0)
The third workaround looks OK to me. You can make strip.lines as small as 
you want as long as it's positive.


Anyway, I would take a different approach (creating a new factor) for what 
you are trying to do:




combine.factors <- function(..., sep = "/",
                            drop = FALSE,
                            reverse = FALSE)
{
    ## each argument in ... should be a factor,
    ## first varies fastest

    dots <- lapply(list(...), as.factor)
    dotlevels <- lapply(dots, levels)
    dotchars <- lapply(dots, as.character)
    final.levels <- dotlevels[[1]]
    if (length(dotlevels) > 1)
        for (i in 2:length(dotlevels))
            final.levels <-
                if (reverse)
                    as.vector(t(outer(dotlevels[[i]],
                                      final.levels,
                                      paste, sep = sep)))
                else
                    as.vector(outer(final.levels,
                                    dotlevels[[i]],
                                    paste, sep = sep))
    final.chars <-
        do.call("paste",
                c(if (reverse) rev(dotchars) else dotchars,
                  list(sep = sep)))
    ans <- factor(final.chars, levels = final.levels)
    if (drop) ans <- ans[, drop = TRUE]
    ans
}


data(barley)
dotplot(variety ~ yield | combine.factors(year, site,
                                          sep = "    ",
                                          reverse = TRUE),
        data = barley, layout = c(2, 6))




Deepayan