1

TukeyHSD 函数打印一个标题“alpha% family-wise confidence level”,它包含在title函数中。因此,使用main = ""删除标题的方法会给出错误消息:

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 建议将其main = ""放入plot.TukeyHSD 函数中。但是,如果我尝试手动编辑该函数,我也会收到一条错误消息:

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

我做错了什么以及如何删除情节中的标题?

4

1 回答 1

1

嗯,这就有点尴尬了。我没有TukeyHSD在绘图功能内部使用。这有效:

tukey.edit(TukeyHSD(z))
于 2012-12-03T10:03:34.150 回答