使用 SjPlot 绘制回归时更改交互项的标签
Changing the label for an interaction term when plotting a regression with 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)
您可以在 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"))
我正在尝试使用 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)
您可以在 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"))