[R] How to auto-scale cex of y-axis labels in lattice dotplot?

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu Jul 26 21:53:16 CEST 2007


On 7/25/07, Kevin Wright <kw.statr at gmail.com> wrote:
> When I create a dotplot in lattice, I frequently observe overplotting
> of the labels along the vertical axis.  On my screen, this illustrates
> overplotting of the letters:
>
> windows()
> reps=6
> dat=data.frame(let=rep(letters,each=reps), grp=rep(1:reps, 26),
>   y=runif(26*reps))
> dotplot(let~y|grp, dat)
>
> Is there a way to automatically scale the labels so that they are not
> over-plotted?

Not that I can think of.

> I currently do something like this:
> Calculate or guess the number of panel rows: NumPanelRows
> cexLab <- min(1, .9*par()$pin[2]/
>               (nlevels(dat$let)*NumPanelRows*strheight("A",units="in")))
> dotplot(..., scales=list(y=list(cex=cexLab))
>
> Is there an easier way?
>
> Is there a function that I can call which calculates the layout of the
> panels that will be used in the dotplot?

Not really. The eventual layout is calculated inside print.trellis as
follows (where 'x' is the "trellis" object being plotted):


    panel.layout <-
        compute.layout(x$layout, dim(x), skip = x$skip)

    [...]

    if (panel.layout[1] == 0)
    {
        ddim <- par("din")
        device.aspect <- ddim[2] / ddim[1]
        panel.aspect <- panel.height[[1]] / panel.width[[1]]

        plots.per.page <- panel.layout[2]
        m <- max (1, round(sqrt(panel.layout[2] * device.aspect /
panel.aspect)))
        n <- ceiling(plots.per.page/m)
        m <- ceiling(plots.per.page/n)
        panel.layout[1] <- n
        panel.layout[2] <- m
    }

-Deepayan



More information about the R-help mailing list