【问题标题】:Cannot change text size in regsubsets plot无法更改 regsubsets 图中的文本大小
【发布时间】:2014-03-09 15:31:44
【问题描述】:

我正在尝试为我的regsubsets 输出绘制一个漂亮的图。我需要使 x 轴标签的字体更小(有 171 个基因,因此不可读)。

我使用的代码是:

regsubsets(x=genes, y=resp, really.big=TRUE, nvmax=4, nbest=10)
plot(a, scale="adjr2", cex=0.5)

我有几个不同的cex 参数(cexcex.axiscex.labcex.maincex.subcex.textcex.names),没有一个可以使字体变小。

似乎解决方案应该很简单,但我想不通!有什么建议吗?

【问题讨论】:

    标签: r plot


    【解决方案1】:

    plot.regsubsets 函数不允许修改 x 轴标签的任何内容。

    查看函数代码:getAnywhere("plot.regsubsets")

    你必须修改这个函数的代码来改变x轴标签的大小。

    plot.regsubsets2 <- 
    function (x, labels = obj$xnames, main = NULL, scale = c("bic", 
        "Cp", "adjr2", "r2"), col = gray(seq(0, 0.9, length = 10)), 
        ...) 
    {
        obj <- x
        lsum <- summary(obj)
        par(mar = c(7, 5, 6, 3) + 0.1)
        nmodels <- length(lsum$rsq)
        np <- obj$np
        propscale <- FALSE
        sscale <- pmatch(scale[1], c("bic", "Cp", "adjr2", "r2"), 
            nomatch = 0)
        if (sscale == 0) 
            stop(paste("Unrecognised scale=", scale))
        if (propscale) 
            stop(paste("Proportional scaling only for probabilities"))
        yscale <- switch(sscale, lsum$bic, lsum$cp, lsum$adjr2, lsum$rsq)
        up <- switch(sscale, -1, -1, 1, 1)
        index <- order(yscale * up)
        colorscale <- switch(sscale, yscale, yscale, -log(pmax(yscale, 
            1e-04)), -log(pmax(yscale, 1e-04)))
        image(z = t(ifelse(lsum$which[index, ], colorscale[index], 
            NA + max(colorscale) * 1.5)), xaxt = "n", yaxt = "n", 
            x = (1:np), y = 1:nmodels, xlab = "", ylab = scale[1], 
            col = col)
        laspar <- par("las")
        on.exit(par(las = laspar))
        par(las = 2)
        axis(1, at = 1:np, labels = labels, ...) # I modified this line
        axis(2, at = 1:nmodels, labels = signif(yscale[index], 2))
        if (!is.null(main)) 
            title(main = main)
        box()
        invisible(NULL)
    }
    

    现在,您可以更改标签的大小:

    library(leaps)
    data(swiss)
    b <- regsubsets(Fertility ~ ., data = swiss, nbest = 2)
    
    plot.regsubsets2(b, cex.axis = 0.75)
    

    【讨论】:

      猜你喜欢
      • 2014-09-16
      • 2020-08-20
      • 2016-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-20
      • 2020-01-03
      相关资源
      最近更新 更多