用 plot.gam 标记参数项的轴

labeling axis for parametric terms with plot.gam

我正在尝试绘制我的 gam 结果。对于所有平滑项(在我的例子中是 1 到 8),绘图效果很好,但如果我想绘制参数项(从 9 开始),我无法更改轴标签。不管我用plot,plot.gam,termplot还是text我都做不到。有小费吗?下面是代码示例

par(mfrow=c(3,3), oma=c(1,1,1,1),pty="s",mar=c(4.5,4.5,1,1)) 
# the first three graphs work perfectly
plot.gam(model$gam,select=1,scale=0,pers=TRUE,all.terms=T,shade=T,xlab="Water depth",ylab="") 
plot.gam(model$gam,select=2,scale=0,pers=TRUE,all.terms=T,shade=T,xlab="Bottom current speed",ylab="")
plot.gam(model$gam,select=3,scale=0,pers=TRUE,all.terms=T,shade=T,xlab="Substance",ylab="")
# this graph for the parametric term is plotted but I cannot change axis labels
plot.gam(model$gam,select=9,scale=0,pers=T,all.terms=T,shade=T,xlab="AIS",ylab="")

如果您使用的是 RStudio,您可以点击 F2 按钮查看 plot.gam 的源代码。在 R 中执行不带括号的 plot.gam。然后你会发现,对于某些 select 值,plot()termplot() 取代。 因此,要操纵 x 轴标签,您必须使用 xlabs 而不是 xlab.

require(mgcv) 
pa <- c(1, rep(0, 9))
term_A <- runif(10, 9, 15)
term_B <- runif(10, 1, 25)
data <- as.data.frame(cbind(pa, term_A, term_B)) 
mod <- gam(pa ~ s(term_A, k=3) + term_B, family=binomial, data=data) 
summary(mod)
par(mfrow=c(2, 2)) 
# xlab=""
plot.gam(mod, select=1, all.terms=T, shade=T, xlab="your own lab title", ylab="") 
# xlabs=""
plot.gam(mod, select=2, all.terms=T, shade=T, xlabs="your own lab title", ylab="")