1

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?

Mikko
  • 7,530
  • 8
  • 55
  • 92

1 Answers1

1

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

tukey.edit(TukeyHSD(z))
Mikko
  • 7,530
  • 8
  • 55
  • 92
  • How did you access the `plot.TukeyHSD` function? When I tried that in R, it says the object is not found, even though I'm able to plot an object of the class `TukeyHSD`. Is that strange? – Heisenberg Mar 13 '15 at 23:45
  • Try `stats:::TukeyHSD.aov`. You will find this through `methods(TukeyHSD)` – Mikko Mar 14 '15 at 03:48
  • Do you know why `plot.TukeyHSD` doesn't work? I suppose this will lead to my deepening understanding of R. – Heisenberg Mar 14 '15 at 03:49
  • Hmmm...a good question. Maybe the code has been changed since this question. I see that your point is correct. You cannot find `plot.TukeyHSD` function any longer. Maybe somebody else knows an answer for this? – Mikko Mar 14 '15 at 03:52
  • @Heisenberg. You could also make a question about this to get some attention from people that might know. – Mikko Mar 14 '15 at 03:57
  • 1
    [Link to the new question](http://stackoverflow.com/questions/29045300/why-is-the-plot-tukeyhsd-method-not-visible) – Heisenberg Mar 14 '15 at 04:01