删除曲线glmnet中的上轴

时间:2016-04-22 23:35:13

标签: r plot glmnet

当使用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)

1 个答案:

答案 0 :(得分: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)