是否可以将多个单变量部分依赖图的结果组合在一个图上?

Is it possible to combine the results of multiple univariate partial dependence plots on a single graph?

我有一个分类随机森林模型,其中包含 3 class 个物种组合和 18 个变量,我想为每个 class 和每个变量构建部分依赖图。我有以下代码行来构建四个图(每个 class 如何与变量“深度”交互)

pdp1.1 <- partial(RFmodel, pred.var = "depth", plot=TRUE, which.class=1, train=train.df, plot.engine= "ggplot") 
pdp1.2 <- partial(model.rf.rf, pred.var = "a_bathym", plot=TRUE, which.class=2, train=train.df, plot.engine= "ggplot")
pdp1.3 <- partial(model.rf.rf, pred.var = "a_bathym", plot=TRUE, which.class=3, train=train.df, plot.engine= "ggplot")

有没有办法将每个部分依赖图的结果组合成一个具有相同 x/y 轴的图形?

如果有帮助,我很乐意提供任何额外的information/code!

这是基本的 ggplot fig 对象的解决方案,我不知道它是否适合你。同时,我会尝试制作一些PDP模型并更新。

library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.0.5
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(ggpubr)

p1 <- iris %>% ggplot(aes(Sepal.Length, Petal.Length)) + geom_point()

p2 <- iris %>% ggplot(aes(Sepal.Length, Petal.Length)) + geom_point()





fig <- ggarrange(p1 + rremove("xlab") + rremove("ylab"), 
                 p2 + rremove("xlab") + rremove("ylab"),  
                 common.legend = T)


fig %>% annotate_figure(left = text_grob("your y-axis", rot = 90),
                        bottom = text_grob("your x-axis"))

reprex package (v2.0.1)

于 2022-02-19 创建