1
votes

Here is a toy example to use for demonstration:

boxplot(1:90 ~ c({1:90} %% 3),names=c("A","B\nB","C\nC\nC"))

If you plot, you will see the motivation for my query. I would like to move the tick mark labels for the groups away from the axis. And, for my own reasons, I do not want to "print nothing" & use axes() function...instead, I want to know how to do this by passing parameters to subroutines called by boxplot(). My understanding is that this should be doable, but I have proven unsuccessful to date.

For example, the solution presented here is far too inelegant for my purposes:
R, Change distance between axis tick marks and tick mark labels

¿Does anyone know how to do this?

1
I'm a bit curious why this is getting no responses... - Gregg H

1 Answers

1
votes

Function boxplot() after checking the syntax of the input arguments calls "bxp" function. Here you can see the arguments it is passing to it:

if (plot) {
    if (is.null(pars$boxfill) && is.null(args$boxfill)) 
        pars$boxfill <- col
    do.call("bxp", c(list(z, notch = notch, width = width, 
        varwidth = varwidth, log = log, border = border, 
        pars = pars, outline = outline, horizontal = horizontal, 
        add = add, at = at), args[namedargs]))
    invisible(z)
} 

Function bxp in its turn calls function "axis" and it looks only at "xaxt", "yaxt", "xaxp", "yaxp", "las", "cex.axis", "col.axis" arguments to draw the axis:

if (axes) {
    ax.pars <- pars[names(pars) %in% c("xaxt", "yaxt", "xaxp", 
        "yaxp", "las", "cex.axis", "col.axis", "format")]
    if (is.null(show.names)) 
        show.names <- n > 1
    if (show.names) 
        do.call("axis", c(list(side = 1 + horizontal, at = at, 
            labels = z$names), ax.pars))
    do.call("Axis", c(list(x = z$stats, side = 2 - horizontal), 
        ax.pars))
}

As you can see from the above, there are no parameters that can change the offset of the X labels that can be passed to boxplot.

With ggplot by default displays the labels the way you want:

df <- data.frame( x= as.factor(c({1:90} %% 3)), y = 1:90 )
ggplot(df,aes(x=x, y=y) ) + 
  geom_boxplot()+ 
  scale_x_discrete(labels=c("A","B\nB","C\nCC\nCCC"))

enter image description here