2012-12-03 48 views
1

TukeyHSD函數打印出一個標題「alpha%family-wise confidence level」,它包含在title函數中。因此,使用main = ""方法來去掉標題給出錯誤信息:如何編輯plot.TukeyHSD中的主標題?

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 = ""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 

我做了什麼錯誤以及如何刪除的情節標題?

回答

1

呃,這有點尷尬。在繪圖功能中我沒有使用TukeyHSD。這工作:

tukey.edit(TukeyHSD(z)) 
+0

你是如何訪問'plot.TukeyHSD'函數?當我在R中嘗試過時,它說沒有找到該對象,即使我能夠繪製「TukeyHSD」類的對象。這很奇怪嗎? – Heisenberg

+0

試試'stats ::: TukeyHSD.aov'。你會通過'方法(TukeyHSD)' – Mikko

+0

找到這個。你知道爲什麼'plot.TukeyHSD'不起作用嗎?我想這會導致我對R的理解加深。 – Heisenberg