從getAnywhere("plot.cld")
我沒有看到你如何能夠明確地改變頂部標籤的字體大小。所以......解決方法之一就是根據自己的需要調整現有的功能:
library(multcomp)
data(warpbreaks)
amod <- aov(breaks ~ tension, data = warpbreaks)
tuk <- glht(amod, linfct = mcp(tension = "Tukey"))
tuk.cld <- cld(tuk)
old.par <- par(mai=c(1, 2,1.25, 1), no.readonly=TRUE)
plot2.cld(tuk.cld, cex.top = 2)
par(old.par)
與
plot2.cld <- function (x, type = c("response", "lp"), ..., cex.top = 1)
{
mcletters <- x$mcletters
msletters <- mcletters$monospacedLetters
vletters <- sapply(msletters, function(x) paste(strsplit(x,
"")[[1]], "\n", collapse = ""))
vletters <- vletters[gsub(" ", "", levels(x$x))]
msletters <- msletters[gsub(" ", "", levels(x$x))]
type <- match.arg(type)
dat <- x[c("x", "y", "lp")]
if (is.null(x$weights)) {
dat$weights <- rep(1, NROW(x$y))
}
else {
dat$weights <- x$weights
}
dat <- as.data.frame(dat)
xn <- x$xname
yn <- x$yname
if (!is.null(list(...)$xlab))
xn <- list(...)$xlab
if (!is.null(list(...)$ylab))
yn <- list(...)$ylab
if (x$covar || type == "lp") {
boxplot(lp ~ x, data = dat, xlab = xn, ylab = "linear predictor",
...)
axis(3, at = 1:nlevels(dat$x), labels = vletters)
}
else {
if (is.integer(dat$y))
dat$y <- as.numeric(dat$y)
switch(class(dat$y), numeric = {
boxplot(y ~ x, data = dat, xlab = xn, ylab = yn,
...)
axis(3, at = 1:nlevels(dat$x), labels = vletters, cex.axis = cex.top)
}, factor = {
at <- xtabs(weights ~ x, data = dat)/sum(dat$weights)
at <- cumsum(at) - at/2
mosaicplot(xtabs(weights ~ x + y, data = dat), main = NULL,
xlab = xn, ylab = yn, ...)
axis(3, at = at, labels = vletters, tick = FALSE, cex.axis = cex.top)
}, Surv = {
plot(survfit(y ~ x, data = dat), lty = 1:nlevels(dat$x),
...)
nc <- nchar(levels(dat$x))
spaces <- unlist(lapply(max(nc) - nc, function(x) return(paste(rep(" ",
x), collapse = ""))))
legend("topright", lty = 1:nlevels(dat$x), legend = paste(levels(dat$x),
spaces, ": ", msletters, sep = ""), ...)
})
}
}
給
非常感謝你,你」已經做了我的一天! –
同意這樣的回答的問題,但相信這是常規的時候,修改功能,給他們一個稍微不同的名稱(通常與尾隨「2」),並把新的參數後點。 '(x,type = c(「response」,「lp」),...,cex.top = 1)'。我還要修改'axis(3,...)'的另一個實例。我會在函數調用的頂部添加'oldpar = par(mai = c(1,cex.top,1.25,1))',然後在退出時恢復par設置。 –