我正在嘗試使用 jtools 包為效果圖編輯 R 中預測變數的因子水平的名稱。我應該能夠使用“pred.labels”引數來做到這一點,但標簽不會改變。例如,使用 mtcars 資料集,我嘗試寫出預測變數名稱(“四”、“六”、“八”),但圖中沒有變化。
data(mtcars)
mtcars$cyl <- factor(mtcars$cyl)
mtest <- lm(mpg ~ cyl hp wt, data = mtcars)
effect_plot(mtest, pred = cyl, pred.labels = c("four", "six", "eight"))

現在,如果這真的是我的問題,我會覆寫資料中的因子水平。但是,在我的資料集中,我有許多因素的名稱中應該有一個空格以便于解釋,所以我不想以這種方式重新編碼我的變數。知道如何解決這個問題嗎?
謝謝
uj5u.com熱心網友回復:
由于jtools似乎使用,ggplot2您可以像使用時一樣更改標簽ggplot2
label <- c("four", "six", "eight")
effect_plot(mtest, pred = cyl) scale_x_discrete(labels= label)
或者
effect_plot(mtest, pred = cyl) scale_x_discrete(labels= c("four", "six", "eight"))

uj5u.com熱心網友回復:
不確定如何在 jtools 中重命名組標簽,但您可以scale_x_discrete在 ggplot2 中進行,因為結果物件來自 ggplot。
effect_plot(mtest, pred = cyl)
scale_x_discrete(labels = c("four", "six", "eight"))

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/371952.html
上一篇:將geom_map與transition_time一起使用會得到錯誤:insert_points(polygon$x,polygon$y,splits,n)中的錯誤
下一篇:缺失資料的時間序列圖
