0

I'm plotting a model with two categorical variables, each with 2 categories. My attempt is to have something like the below:

enter image description here

Instead what I have is this:

enter image description here

Here is my code:

install.packages("sjstats")
library(sjstats)
install.packages("sjPlot")
library(sjPlot)

plot_model(my_model, type = "pred", terms = c("Language", "Switching"),
           axis.title = "Response Times (log)", legend.title = "Condition",
           colors = "Set2", dot.size = 3, line.size = 1.5, ci = TRUE, ci.lvl = 0.95)

Sorry for not being able to share the model or a small reproducible part of it, but I'm not able to subset from it using dput and I'm not yet able to share the whole dataset on here.

My issue is more in the arguments that I'm using to show the whiskers of the plot the confidence intervals but they don't seem to work for some reason. Also, any suggestions on how to get the vertical line? vline arguments don't work either...

EDIT: After editing with the suggested code below by neilfws, this is what I get:

enter image description here

Orestes_Fox
  • 189
  • 11

1 Answers1

1

The output from plot_model is as expected with the given arguments. The function does not plot whiskers for this kind of model.

However, the output from plot_model is a ggplot object, so you can modify it by adding geoms.

Here is a simple example. You'll need to share some data if you want code more suited to your data.

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

fit <- mtcars %>% 
  mutate(am = factor(am)) %>% 
  glm(vs ~ am, ., family = 'binomial')

plot_model(fit, type = "pred", terms = "am") + 
geom_errorbar(
    aes(ymin = conf.low, ymax = conf.high),
    width = 0.25) + 
geom_line()

Result:

enter image description here

neilfws
  • 32,751
  • 5
  • 50
  • 63
  • Actually, I just rerun it and noticed the vertical line is shifted and it seems to insert another pair of error bars. I've added these to my post above. – Orestes_Fox May 15 '23 at 21:28
  • 1
    Try removing the extra arguments `ci`, `ci.lvl` and `line.size` from `plot_model`. – neilfws May 15 '23 at 22:28
  • I tried that leaving only ```plot_model(RT_lmer_full, type = "pred", terms = c("Language", "Switching"), axis.title = "Response Times (log)", legend.title = "Condition") + geom_errorbar(aes(ymin = conf.low, ymax = conf.high), width = 0.25) + geom_line()``` but the result is still two lines, just smaller width. Not sure what I'm doing wrong. – Orestes_Fox May 16 '23 at 20:27
  • 1
    We'll need to see your data, or at least some [example data](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with the same structure, to help further. – neilfws May 16 '23 at 22:29
  • I think my brain is a bit dried out from trying to submit my thesis soon. I figured out a solution: using a different function. It seems like plot_model calls the line and dot arguments somehow and they duplicate when I try to add any arguments for error bar, etc. Instead what I did was: ```cat_plot(RT_lmer_full, pred = Language, modx = Switching, geom = "line", interval = TRUE, int.type="confidence", int.width = 0.95, line.thickness = 1.5, pred.point.size = 1.5, colors="Set2")``` And this gave me exactly the above example graph, no duplications of lines. – Orestes_Fox May 16 '23 at 22:42