I have a group of models that I am plotting together in R using the plot_models
function from the sjPlot
package. The models are plotting confidence intervals for similar felm
regressions that use different datasets. All the models share the same variables of interest, and their confidence intervals occupy the same ranges. I have successly plotted all of the models, however, I now cannot order them how would be ideal.
My code is the following:
placebo_models <- paste0("outcome", 1:13, " ~ Variable1 + Variable2 | fe_variable |0| fe_variable") |> lapply(\(x) felm(as.formula(x), data = df))
models_list <- list(placebo_models[[13]], placebo_models[[12]], placebo_models[[11]], placebo_models[[10]], placebo_models[[9]], placebo_models[[8]], placebo_models[[7]], placebo_models[[6]], placebo_models[[5]], placebo_models[[4]], placebo_models[[3]], placebo_models[[2]], placebo_models[[1]])
testplot <- plot_models(models_list, colors = c("RED"), show.values = TRUE, p.threshold = 0.05, spacing = 0.8, dot.size = 1, digits = 5, title = "Placebo Models", axis.labels = c("Variable1", "Variable2")) + scale_color_discrete(labels = c("m1", "m2", "m3", "m4", "m5", "m6", "m7", "m8", "m9", "m10", "m11", "m12", "m13"))
My current plot output is the following:
Ideally, I would like to change this model to report in order (descending from the top) m1's Variable 1 confidence interval, followed by m1's Variable 2 confidence interval, before going to m2 (Variable1, then Variable2), m3 (Variable1, then Variable2), etc.
Is there a way to reorder the plotted lines such that this is possible? The variables are identical across all the models, so it should fit, as long as it can be restructured. Can the variables of different models be reordered and inter-mixed within the same plot like so?
I am unfortunately not able to share the original data, but this visualization should explain the problem. Many thanks!