2016-04-22 49 views
0

當使用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) 
+0

這將是如果有用你可以在這裏提供可重現的樣品。你使用了哪些代碼,你指的是哪一個plot函數? – Laterow

+0

請參閱上文。謝謝。 – milan

回答

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)