使用 plot_model() 为多面板图设置相同的 y-lim

Set same y-lim for multi panel plot using plot_model()

我使用 plot_model() 创建了一个多面板图。但是,y_axis 的比例限制对于每个面板都是不同的。

我首先 运行 一个模型 fm 然后绘制预测值:

p <-  plot_model(
  fm,
  type = c("pred"),
  terms = c("Trial","CS [-0.9,0,0.9]", "Prof[-10.9,0,10.9]", "Congr"))

然后我想在所有面板上获得相同的 y 轴刻度(限制):

 p + ggplot2::scale_y_continuous(limits = c(5.9, 6.2))

但这没有用!

感谢任何帮助!

谢谢! 这似乎可行,但前提是我将面板最小化,即将每个面板放在单独的图上:

Panel1 Panel

当我想在同一图中显示两个面板并使用所需的 Y 限制时,没有任何变化。

Panels 1&2

这是因为情节的大小有限吗?

这是一个可重现的例子:

df <- structure(list(Subject = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L), Log_RT = c(5.955837369, 6.228511004, 5.874930731, 
5.84932478, 5.780743516, 5.866468057, 5.424950017, 5.81711116, 
5.899897354, 5.834810737, 5.683579767, 5.655991811, 5.624017506, 
5.459585514, 5.697093487, 5.934894196, 5.802118375, 5.834810737, 
5.789960171, 5.631211782, 5.796057751, 5.669880923, 5.549076085, 
5.81711116, 6.03068526, 6.040254711, 5.81711116, 5.80814249, 
5.863631176, 5.641907071, 6.033086222, 6.021023349, 6.470799504, 
6.380122537, 6.424869024, 6.29156914, 6.061456919, 6.502790046, 
6.282266747, 6.311734809, 6.455198563, 6.259581464, 6.570882962, 
6.371611847, 6.570882962, 6.483107351, 6.333279628, 6.455198563, 
6.469250317, 6.289715571, 6.285998095, 6.442540166, 6.289715571, 
6.395261598, 6.152732695, 6.415096959, 6.352629396, 6.270988432, 
6.210600077, 6.311734809, 6.059123196, 6.208590026), CSC = c(-0.562217385, 
-0.562217385, -0.562217385, -0.562217385, -0.562217385, -0.562217385, 
-0.562217385, -0.562217385, -0.562217385, -0.562217385, -0.562217385, 
-0.562217385, -0.562217385, -0.562217385, -0.562217385, -0.562217385, 
-0.562217385, -0.562217385, -0.562217385, -0.562217385, -0.562217385, 
-0.562217385, -0.562217385, -0.562217385, -0.562217385, -0.562217385, 
-0.562217385, -0.562217385, -0.562217385, -0.562217385, -0.145550719, 
-0.145550719, -0.145550719, -0.145550719, -0.145550719, -0.145550719, 
-0.145550719, -0.145550719, -0.145550719, -0.145550719, -0.145550719, 
-0.145550719, -0.145550719, -0.145550719, -0.145550719, -0.145550719, 
-0.145550719, -0.145550719, -0.145550719, -0.145550719, -0.145550719, 
-0.145550719, -0.145550719, -0.145550719, -0.145550719, -0.145550719, 
-0.145550719, -0.145550719, -0.145550719, -0.145550719, -0.145550719, 
-0.145550719), Trial = c(-14.60970149, -13.60970149, -12.60970149, 
-11.60970149, -10.60970149, -9.609701493, -8.609701493, -7.609701493, 
-6.609701493, -5.609701493, -4.609701493, -3.609701493, -2.609701493, 
-1.609701493, -0.609701493, 0.390298507, 1.390298507, 2.390298507, 
3.390298507, 4.390298507, 6.390298507, 7.390298507, 8.390298507, 
9.390298507, 10.39029851, 11.39029851, 12.39029851, 13.39029851, 
14.39029851, 15.39029851, -15.60970149, -14.60970149, -13.60970149, 
-12.60970149, -11.60970149, -10.60970149, -9.609701493, -8.609701493, 
-7.609701493, -6.609701493, -5.609701493, -4.609701493, -3.609701493, 
-2.609701493, -1.609701493, -0.609701493, 0.390298507, 1.390298507, 
2.390298507, 3.390298507, 4.390298507, 5.390298507, 6.390298507, 
7.390298507, 8.390298507, 9.390298507, 10.39029851, 11.39029851, 
12.39029851, 13.39029851, 14.39029851, 15.39029851), Congr.d = c(1L, 
0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 
1L, 0L, 0L, 1L, 1L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 
1L, 0L, 1L, 1L, 0L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 1L, 0L, 0L, 1L, 
1L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 1L, 0L, 0L, 1L), ProC = c(7.814814815, 
7.814814815, 7.814814815, 7.814814815, 7.814814815, 7.814814815, 
7.814814815, 7.814814815, 7.814814815, 7.814814815, 7.814814815, 
7.814814815, 7.814814815, 7.814814815, 7.814814815, 7.814814815, 
7.814814815, 7.814814815, 7.814814815, 7.814814815, 7.814814815, 
7.814814815, 7.814814815, 7.814814815, 7.814814815, 7.814814815, 
7.814814815, 7.814814815, 7.814814815, 7.814814815, 12.25925926, 
12.25925926, 12.25925926, 12.25925926, 12.25925926, 12.25925926, 
12.25925926, 12.25925926, 12.25925926, 12.25925926, 12.25925926, 
12.25925926, 12.25925926, 12.25925926, 12.25925926, 12.25925926, 
12.25925926, 12.25925926, 12.25925926, 12.25925926, 12.25925926, 
12.25925926, 12.25925926, 12.25925926, 12.25925926, 12.25925926, 
12.25925926, 12.25925926, 12.25925926, 12.25925926, 12.25925926, 
12.25925926)), class = "data.frame", row.names = c(NA, -62L))

对于情节:

library(jtools)
library(sjPlot)
library(pbkrtest)

fm <- lmer(Log_RT ~ Congr.d*CSC*Trial*ProC +
              (1+Congr.d||Subject), data=df)

summ(fm)



plot_model(fm, type = c("pred"),terms = c("Trial","CSC [-0.2,0,0.2]",
 "ProC[-2.2,0,2.2]", "Congr.d[0,1]"),axis.lim=c(6.2,6.8)) 

Plot

您可以看到 Y 轴限制与代码中指示的不同。

您可以使用 ggeffects-package, which is internally used by sjPlot to create effects-plots. ggeffects gives you some more flexibility according to plot-customization. In your case, you can simply use arguments that are passed down to ggplot2::scale_y_continuous(), see details in this vignette:

library(lme4)
library(ggeffects)

fm <- lmer(Log_RT ~ Congr.d*CSC*Trial*ProC + (1+Congr.d||Subject), data=df)
pr <- ggpredict(fm, terms = c("Trial","CSC [-0.2,0,0.2]", "ProC[-2.2,0,2.2]", "Congr.d[0,1]"))
plot(pr, limits = c(6.0, 7.0))

reprex package (v0.3.0)

于 2019-12-23 创建