使用SjPlot绘制回归时更改交互项的标签

时间:2020-03-07 02:05:53

标签: r sjplot

我正在尝试使用sjPlot绘制包含多个交互项的回归系数。我更改了所有变量的标签,以使它们更易于理解,但是不幸的是,交互仅显示为variable_1:variable_2。

是否有一种方法可以修改这些交互的输出,使其显示为“ label_1 x label_2”或类似的效果?

这是一个例子:

data(mtcars)

library(ggplot2)
library(sjPlot)
library(sjlabelled)
library(dplyr)

mtcars <- mtcars %>% var_labels(
  mpg = "Miles per Gallon",
  cyl = "Cylinder"
)

x <- lm(hp ~ mpg*cyl, data=mtcars)

plot_model(x)

1 个答案:

答案 0 :(得分:1)

您可以在scale_x_discrete函数中添加标签。这样做无需在变量中添加var_labels。

data(mtcars)
x <- lm(hp ~ mpg*cyl, data=mtcars) 

plot_model(x) +
  scale_x_discrete(labels=list(
    mpg = "Miles per Gallon", 
    cyl = "Cylinders",
    `mpg:cyl` = "Miles per Gallon : Cylinders"))

enter image description here