Skip to content

Fitting long names in boxplot

1 message · Gavin Simpson

#
On Fri, 2008-02-29 at 14:40 -0800, Alex Reynolds wrote:
Look at ?par and argument/parameter 'las', which controls the
orientation of axis tick labels.

You'll also need to increase the margin size on the side of the plot
holding the labels if they are very long. For this, see ?par again and
parameters 'mar' or 'mai' depending on how you wish to define the margin
size.

## Example
dat <- data.frame(values = rnorm(100), group = gl(2, 50))
levels(dat$group) <- c("reallyreallylonglabel", 
                       "anevenlooooooooooooongerlabel")
## las = 1 gets y-axis labels horizontal, but note note enough room
boxplot(values ~ group, data = dat, horizontal = TRUE, las = 1)

## so change the margin on the left (no. 2)
## default is c(5, 4, 4, 2) + 0.1
## and shrink text size so we don't need a huge margin
op <- par(mar = c(5, 10, 4, 2) + 0.1)
boxplot(values ~ group, data = dat, horizontal = TRUE, las = 1, 
        cex.axis = 0.7)
## reset the plotting parameters
par(op)

HTH

G