[R] put strip below the panel (dotplot)

Peter Ehlers ehlers at ucalgary.ca
Thu Feb 28 23:58:53 CET 2013


On 2013-02-28 04:20, Elaine Kuo wrote:
> Hello
>
>
>
> I am using lattice dotplot and I would like to put the strip under the
> panel.
>
> I found the code “strip” is for the strip above the panel, and “strip.left”
> for the strip left to the panel.
>
> Please kindly advise how to write the code for the strip under the panel
>
> Thank you
>
>
> Elaine
>

I don't think that this is trivial. I would just use panel.text() and
panel.rect() to create my own strips. [I do wonder why you would want
to have the strips at the bottom - seems unnatural to me.]

Here's a start, using the iris data:

   dotplot(Sepal.Length ~ Petal.Length | Species, data=iris,
      layout = c(3, 1),
      ylim = c(-2, 37),    ## adjust y-range to leave a bit
                           ##  of space at bottom
      strip = FALSE,       ## omit top strips
      panel = function(...){
        cp <- current.panel.limits()
        stripheight <- (cp$ylim[2] - cp$ylim[1]) / 25
                           ## may have to adjust the '25'
        xleft <- cp$xlim[1]
        xright <- cp$xlim[2]
        ybottom <- cp$ylim[1]
        ytop <- cp$ylim[1] + stripheight
        lab <- levels(iris$Species)[panel.number()]
        panel.dotplot(...)
        panel.rect(xleft, ybottom, xright, ytop, fill = "bisque")
        panel.text(x = (xleft + xright) / 2,
                   y = (ybottom + ytop) / 2,
                   labels = lab)
      })


Peter Ehlers



More information about the R-help mailing list