如何在R中的multcomp包中的plot.cld()中增加紧凑字母显示的大小

时间:2016-11-27 09:33:53

标签: r

可能是一个愚蠢的问题:如何增加plot.cld()顶部字母的大小?例如,如何增加显示字母的尺寸' a' a'' a'在下面的情节?有意思的是,我不是唯一面临这种烦恼的人。提前谢谢!

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,1,1.25,1), no.readonly=TRUE)
plot(tuk.cld)
par(old.par)

1 个答案:

答案 0 :(得分:1)

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 = ""), ...)
        })
    }
}

enter image description here