图形显示为空白。
我需要从GBM分析中绘制几个图形,因此我正在使用循环和粘贴功能。
但是,所有显示的图像都空白吗?会是什么 在循环外执行代码时,一切正常。谢谢
list <- list("A","B", "C")
for (i in list) {
df <- fread(paste("data_", i, ".csv", sep = ""), header = TRUE)
gbm.fit <- gbm( formula = y ~ ., distribution = "gaussian", data = train,n.trees = 1000, interaction.depth = 5, shrinkage = 0.1, cv.folds = 5, n.cores = NULL, verbose = FALSE )
pathname <- paste("gbm", i, ".tiff", sep = "")
tiff( file = pathname, width = 1200, height = 1000, res = 105 )
vip( gbm.fit, num_features = 15, bar = TRUE, width = 0.75, horizontal = TRUE, color = hcl.colors( 15, palette = "Greens2", alpha = NULL, rev = FALSE, fixup = TRUE ), fill = hcl.colors( 15, palette ="Greens", alpha = NULL, rev = TRUE, fixup = TRUE ) )
dev.off()
}
我希望图形带有正确的内容
该vip
函数使用ggplot2
基于图形的图形。因此,可以print()
使用图解或将ggsave()
其保存到文件中:
1.print()
方法:
myPlot <- vip( gbm.fit, num_features = 15, bar = TRUE, width = 0.75, horizontal = TRUE,
color = hcl.colors( 15, palette = "Greens2", alpha = NULL, rev = FALSE,
fixup = TRUE ), fill = hcl.colors( 15, palette ="Greens", alpha = NULL,
rev = TRUE, fixup = TRUE ) )
tiff( file = pathname, width = 1200, height = 1000, res = 105 )
print(myPlot)
dev.off()
2.ggsave()
方法:
myRes <- 105 # ggsave uses inches, not pixels
ggsave(pathname, myPlot, device = "tiff", width = 1200 / myRes,
height = 1000 / myRes, dpi = myRes)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句