问题描述
我试图在随机效应图中更改变量标签的名称,但找不到方法。对于常规情节,我只会使用 axis.labels
但对于 type = re
我找不到方法。
如何将文本从“country(Intercept)”和“kNowledge_adj”更改为其他内容,例如“pais(Intercept)”和“Conhecimento politico”?
创建数据的代码:
structure(list(country = c("Germany","Brazil","Czech Republic","New Zealand","Ireland","Sweden","Netherlands","Germany","Hungary","Portugal","Portugal"),exp_cong_LH_all = c(NA,NA,-3,-1,-6.5,-2,-5,-4,-6,-1.5,-0.5,-7,-2.5,-8,-3.5,NA),kNowledge_adj = c(0.333333333333333,0.666666666666667,0.333333333333333,NaN,1,0.5,0.666666666666667)),row.names = c(NA,-850L),class = "data.frame")
回归和绘图:
library(sjplot)
VS1 <- lmertest::lmer(exp_cong_LH_all ~ kNowledge_adj + (1 + kNowledge_adj|country),data = df)
plot_model(VS1,type = "re") +
scale_color_sjplot("eight")
解决方法
也许有更好的方法,但这里需要考虑一些可能会有所帮助的方法。
首先,将您的 plot_model
结果(ggplot
)存储为 pm
。
pm <- plot_model(VS1,type = "re") +
scale_color_sjplot("eight")
您将看到 pm$data$facet
存储感兴趣的标签:
pm$data$facet
[1] "country (Intercept)" "country (Intercept)" "country (Intercept)" "country (Intercept)" "country (Intercept)"
[6] "country (Intercept)" "country (Intercept)" "country (Intercept)" "country (Intercept)" "knowledge_adj"
[11] "knowledge_adj" "knowledge_adj" "knowledge_adj" "knowledge_adj" "knowledge_adj"
[16] "knowledge_adj" "knowledge_adj" "knowledge_adj"
您可以转换为因子,并注意级别将包括以下标签:
pm$data$facet <- factor(pm$data$facet)
levels(pm$data$facet)
[1] "country (Intercept)" "knowledge_adj"
将级别更改为新标签和绘图:
levels(pm$data$facet) <- c("pais(Intercept)","Conhecimento político")
pm
情节