我是 {shapviz} 软件包的最新用户,我在自定义图表(例如重要性图表)时遇到了一些困难。
我想要,例如:
theme(legend.key.size = unit(2, 'cm')
];show_numbers = TRUE
) [就像我使用 geom_text( )、geom_label( )
或 annotation( )
函数]。由于 shapviz 图是 ggplot 类型,我尝试通过访问列表或添加图层来更改它们,但没有成功。
谢谢!
使用一些玩具数据,您可以通过以下方式改变这些美学:
library(xgboost)
library(shapviz)
library(viridis)
library(ggplot2)
X_train <- data.matrix(iris[, -1])
dtrain <- xgb.DMatrix(X_train, label = iris[, 1], nthread = 1)
fit <- xgb.train(data = dtrain, nrounds = 10, nthread = 1)
x <- shapviz(fit, X_pred = X_train)
p <- sv_importance(x, kind = "both", show_numbers = TRUE) +
scale_colour_gradient(low = "darkblue", high = "skyblue",
breaks = c(0, 1), labels = c("low", "high")) +
labs(colour = "My Title") +
theme(legend.key.size = unit(2, 'cm'),
legend.title.position = "left",
legend.title = element_text(angle = 90, hjust = 0.5)
)
p$layers[[1]]$aes_params$fill <- "red"
p$layers[[4]]$aes_params$fontface <- "italic"
p
创建于 2024-04-08,使用 reprex v2.1.0