我有一個包含 3 類物種組合和 18 個變數的分類隨機森林模型,我想為每個類和每個變數構建部分依賴圖。我有以下代碼行用于構建四個圖(每個類如何與該變數“深度”互動)
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 軸的單個圖?
如果有幫助,我很樂意提供任何其他資訊/代碼!
uj5u.com熱心網友回復:
這是基本 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 包(v2.0.1)創建于 2022-02-19
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/429483.html
上一篇:試圖用兩條線制作一個ggplot
下一篇:R閃亮圖未出現{R}
