[R] labels in (box)plot
Peter Ehlers
ehlers at ucalgary.ca
Sat Sep 25 12:53:02 CEST 2010
On 2010-09-21 8:23, Ivan Calandra wrote:
> Dear users,
>
> I would like all the ticks on a boxplot (x and y) to be labeled
> I have checked all the par() arguments but couldn't find what I'm
> looking for
>
> Here is an example to show it:
> df<- structure(list(SPECSHOR = structure(c(1L, 1L, 1L, 3L, 3L, 3L, 3L,
> 3L, 4L, 4L), .Label = c("cotau", "dibic", "eqgre", "gicam"), class =
> "factor"), Sq122.median = c(2.335835, 1.76091, 1.64717, 1.285505,
> 1.572405, 1.86761, 1.82541, 1.62458, 0.157813, 0.864523)), .Names =
> c("SPECSHOR", "Sq122.median"), class = "data.frame", row.names = c(9L,
> 16L, 23L, 74L, 83L, 90L, 98L, 109L, 121L, 139L))
>
> par(mfrow=c(2,2)) ## not necessary in that example, but I do need it
> with my real data
> boxplot(Sq122.median~SPECSHOR, data=df, horizontal=TRUE) ## the upper
> label on the y-axis (gicam) is not shown
>
> I know I can decrease the size of the labels by setting cex.axis=0.8,
> but I would prefer that all labels are always there, independent of
> their size, without me setting their size explicitly, and even if they
> then overlap.
>
> Am I clear? Is it possible, and how?
>
> Thanks in advance
> Ivan
>
Two suggestions:
1) use staxlab() in the plotrix package (but the staggered
labels might look a bit strange if you have short labels).
library(plotrix)
boxplot(Sq122.median~SPECSHOR, data=df, horizontal=TRUE, axes=FALSE)
box(); axis(1)
staxlab(side=2, at=1:4, lab=levels(df$SPECSHOR), cex=.8)
2) use mtext() to control your labelling.
boxplot(Sq122.median~SPECSHOR, data=df, horizontal=TRUE, axes=FALSE)
box(); axis(1)
axis(2, at=1:4, lab=NA)
mtext(levels(df$SPECSHOR), side=2, at=1:4, line=1, cex=0.8)
-Peter Ehlers
More information about the R-help
mailing list