我无法在gbm模型的局部图上更改x和y标签。我需要为期刊文章重命名它们。
我读了这个并创建了如下图:
library(gbm)
final<- readRDS(final_gbm_model)
summary(final, n.trees=final$n.trees)
以下是摘要输出:
var rel.inf
ProbMn50ppb ProbMn50ppb 11.042750
ProbDOpt5ppm ProbDOpt5ppm 7.585275
Ngw_1975 Ngw_1975 6.314080
PrecipMinusETin_1971_2000_GWRP PrecipMinusETin_1971_2000_GWRP 4.988598
N_total N_total 4.776950
DTW60YrJurgens DTW60YrJurgens 4.415016
CVHM_TextZone CVHM_TextZone 4.225048
RiverDist_NEAR RiverDist_NEAR 4.165035
LateralPosition LateralPosition 4.036406
CAML1990_natural_water CAML1990_natural_water 3.720303
PctCoarseMFUpActLayer PctCoarseMFUpActLayer 3.668184
BioClim_BIO12 BioClim_BIO12 3.561071
MFDTWSpr2000Faunt MFDTWSpr2000Faunt 3.383900
PBot_krig PBot_krig 3.362289
WaterUse2 WaterUse2 3.291040
AVG_CLAY AVG_CLAY 3.280454
Age_yrs Age_yrs 3.144734
MFVelSept2000 MFVelSept2000 3.064030
AVG_SILT AVG_SILT 2.882709
ScreenLength ScreenLength 2.683542
HydGrp_C HydGrp_C 2.666106
AVG_POR AVG_POR 2.563147
MFVelFeb2000 MFVelFeb2000 2.505106
HiWatTabDepMin HiWatTabDepMin 2.421521
RechargeAnnualmmWolock RechargeAnnualmmWolock 2.252706
我可以创建一个部分依赖图,如下所示:
plot(final,"ProbMn50ppb",n.trees=final$n.trees)
plot(final,"ProbMn50ppb",n.trees=final$n.trees,ylab="LNNO3")
Error in plot.default(X$X1, X$y, type = "l", xlab = x$var.names[i.var], :
formal argument "ylab" matched by multiple actual arguments
如何更改y轴和x轴标签?
答案 0 :(得分:5)
plot.gbm
函数将自己的名称传递给通用绘图函数,这样两者就会发生冲突。因此,您将无法在该模式下以您希望的方式自定义绘图。但是当你设置return.grid=TRUE
时,作者确实提供了另一种选择。它不是构建绘图,而是输出数据本身。然后,您可以将其用于包括ggplot2在内的任何绘图。
plotdata <- plot(gbm1, return.grid=TRUE)
plot(plotdata, type="l", ylab="ylab", xlab="xlab")
来自帮助(gbm)的示例数据
答案 1 :(得分:1)
您也可以在绘图之前(或在函数中)更改gbm对象:
your_gbm_obj$var.names[index] = "axis label"