2015-04-02 74 views
0

我一直使用lars包进行套索回归的一些工作,并且已经计算出了很多。它输出的图形对我来说仍然是一个谜。我试图编辑plot.lars函数来更改剧情标题,尝试在剧情调用中插入main =“TITLE”,它只是将标题放在现有标题上。任何人都知道我可以如何更改情节调用上方的“LASSO”文本?从lars包更改标题标题

library(lars) 
data(diabetes) # load the data set 
LL = lars(diabetes$x,diabetes$y,type="lasso") 
plot(LL,xvar="step") 
+0

我想出了另一个问题,即par(c ol.main =“#00000000”)是一种至少使标题透明的方法。仍然不能得到另一个,并想知道是否有人有更好的解决方案? – 2015-04-02 15:56:22

回答

1

我想你必须破解这样的绘制方法(我评论的title命令):

plot.lars <- function (x, xvar = c("norm", "df", "arc.length", "step"), breaks = TRUE, 
         plottype = c("coefficients", "Cp"), omit.zeros = TRUE, eps = 1e-10, 
         ...) 
{ 
    object <- x 
    plottype <- match.arg(plottype) 
    xvar <- match.arg(xvar) 
    coef1 <- object$beta 
    if (x$type != "LASSO" && xvar == "norm") 
    coef1 = betabreaker(x) 
    stepid = trunc(as.numeric(dimnames(coef1)[[1]])) 
    coef1 <- scale(coef1, FALSE, 1/object$normx) 
    if (omit.zeros) { 
    c1 <- drop(rep(1, nrow(coef1)) %*% abs(coef1)) 
    nonzeros <- c1 > eps 
    cnums <- seq(nonzeros)[nonzeros] 
    coef1 <- coef1[, nonzeros, drop = FALSE] 
    } 
    else cnums <- seq(ncol(coef1)) 
    s1 <- switch(xvar, norm = { 
    s1 <- apply(abs(coef1), 1, sum) 
    s1/max(s1) 
    }, df = object$df, arc.length = cumsum(c(0, object$arc.length)), 
    step = seq(nrow(coef1)) - 1) 
    xname <- switch(xvar, norm = "|beta|/max|beta|", df = "Df", 
        arc.length = "Arc Length", step = "Step") 
    if (plottype == "Cp") { 
    Cp <- object$Cp 
    plot(s1, Cp, type = "b", xlab = xname, main = object$type, 
     ...) 
    plot(s1, Cp, type = "b", xlab = xname, #main = object$type, 
     ...) 
    } 
    else { 
    matplot(s1, coef1, xlab = xname, ..., type = "b", pch = "*", 
      ylab = "Standardized Coefficients") 
    #title(object$type, line = 2.5) 
    abline(h = 0, lty = 3) 
    axis(4, at = coef1[nrow(coef1), ], labels = paste(cnums), 
     cex = 0.8, adj = 0) 
    if (breaks) { 
     axis(3, at = s1, labels = paste(stepid), cex = 0.8) 
     abline(v = s1) 
    } 
    } 
    invisible() 
} 

然后:

plot(LL,xvar="step", main = "my title") 

plot(LL,xvar="step") 
title("my title", line = 3) 
+0

谢谢你,我想对于那些只是编写一个新版本的函数的硬编码的软件包来说,是最简洁的方法。再次感谢。 – 2015-04-02 16:49:49