2016-11-27 47 views
1

可能是一個愚蠢的問題:如何增加plot.cld()頂部的字母大小?例如,如何在下列圖表中增加顯示字母'b','a','a'的大小?我不是唯一面臨這種煩惱的人。提前致謝!如何增加plot.cld()中multcomp包中的緊湊字母顯示的大小R

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

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

+0

非常感謝你,你」已經做了我的一天! –

+1

同意這樣的回答的問題,但相信這是常規的時候,修改功能,給他們一個稍微不同的名稱(通常與尾隨「2」),並把新的參數後點。 '(x,type = c(「response」,「lp」),...,cex.top = 1)'。我還要修改'axis(3,...)'的另一個實例。我會在函數調用的頂部添加'oldpar = par(mai = c(1,cex.top,1.25,1))',然後在退出時恢復par設置。 –