Mikko
Mikko

Reputation: 7755

How to edit main title in plot.TukeyHSD?

TukeyHSD function prints a title "alpha% family-wise confidence level", which is wrapped inside title function. Therefore, using main = "" approach to remove the title gives an error message:

x <- rnorm(20,5,6)
y <- factor(c(rep("d", 5), rep("i",5), rep("t",5), rep("l",5)))

z <- aov(x ~ y)

plot(TukeyHSD(z), main = "")

Error in plot.default(c(xi[, "lwr"], xi[, "upr"]), rep.int(yvals, 2),  : 
  formal argument "main" matched by multiple actual arguments

Joris Meys suggests placing main = "" into the plot.TukeyHSD function. However, if I try to manually edit the function, I get an error message too:

tukey.edit <- function (x, ...) 
{
    for (i in seq_along(x)) {
        xi <- x[[i]][, -4, drop = FALSE]
        yvals <- nrow(xi):1
        dev.hold()
        on.exit(dev.flush())
        plot(c(xi[, "lwr"], xi[, "upr"]), rep.int(yvals, 2), 
            type = "n", axes = FALSE, xlab = "", ylab = "", main = "", # changed main = NULL to main = ""
            ...)
        axis(1, ...)
        axis(2, at = nrow(xi):1, labels = dimnames(xi)[[1L]], 
            srt = 0, ...)
        abline(h = yvals, lty = 1, lwd = 0.5, col = "lightgray")
        abline(v = 0, lty = 2, lwd = 0.5, ...)
        segments(xi[, "lwr"], yvals, xi[, "upr"], yvals, ...)
        segments(as.vector(xi), rep.int(yvals - 0.1, 3), as.vector(xi), 
            rep.int(yvals + 0.1, 3), ...)
        title(xlab = paste("Differences in mean levels of", 
            names(x)[i])) # removed main from here
        box()
    }
}

tukey.edit(z)

Error in x[[i]][, -4, drop = FALSE] : incorrect number of dimensions

What did I do wrong and how to remove the title in the plot?

Upvotes: 1

Views: 2677

Answers (1)

Mikko
Mikko

Reputation: 7755

Eh, this is a little bit embarrassing. I did not use TukeyHSD inside the plotting function. This works:

tukey.edit(TukeyHSD(z))

Upvotes: 1

Related Questions