【问题标题】:Remove upper axis in plot glmnet删除绘图 glmnet 中的上轴
【发布时间】:2016-04-22 23:35:12
【问题描述】:

当使用 glmnet 并绘制系数路径图时,我想删除图上方的轴。

如何移除这个轴?我在网上找到了这个玩具示例:

library(glmnet)
age <- c(4,8,7,12,6,9,10,14,7) 
gender <- c(1,0,1,1,1,0,1,0,0) ; gender<-as.factor(gender)
bmi_p <- c(0.86,0.45,0.99,0.84,0.85,0.67,0.91,0.29,0.88) 
m_edu <- c(0,1,1,2,2,3,2,0,1); m_edu<-as.factor(m_edu)
p_edu <- c(0,2,2,2,2,3,2,0,0); p_edu<-as.factor(p_edu)
f_color <- c("blue", "blue", "yellow", "red", "red", "yellow", "yellow", "red", "yellow")
asthma <- c(1,1,0,1,0,0,0,1,1)
f_color <- as.factor(f_color)
xfactors <- model.matrix(asthma ~ gender + m_edu + p_edu + f_color)[,-1]
x <- as.matrix(data.frame(age, bmi_p, xfactors))
glmmod<-glmnet(x,y=as.factor(asthma),alpha=1,family='binomial')
plot(glmmod,xvar="lambda", axes=FALSE)

【问题讨论】:

  • 如果您能在此处提供可重现的样本,将会很有用。你用了什么代码,你指的是哪个绘图函数?
  • 请见上文。谢谢。

标签: r plot glmnet


【解决方案1】:

我猜这个不需要的轴是用axis 函数制作的。我们可以再使用一次这个函数来覆盖它。诀窍如下:

1) 创建一个包含许多要绘制刻度线的点的序列。

2) 让它们变大(向上拉长)

3) 放大轴的宽度

4) 更改白色并关闭标签

plot(glmmod, xvar = "lambda", axes = F, xlab = "", ylab = "")
axis(side = 3,
     at = seq(par("usr")[1], par("usr")[2], len = 1000), 
     tck = -0.5,
     lwd = 2, 
     col = "white", 
     labels = F)

【讨论】:

    猜你喜欢
    • 2010-11-12
    • 2013-05-05
    • 2012-03-06
    • 2021-04-21
    • 1970-01-01
    • 1970-01-01
    • 2022-10-07
    • 1970-01-01
    • 2021-09-30
    相关资源
    最近更新 更多