Plot using ggplot2

Hello,

I want to plot the results of the following binomial mixed-effects model:

m1 <- glmer(position ~ language + type_verb + definiteness + language:type_verb + language:definiteness + type_verb:definiteness + (1 | subject), data = test, family = binomial(link = "logit"))

I plotted the results using the ggpredict() and plot() functions:

ggpredict(m1, terms = c("language", "type_verb")) %>% plot()

I got the below plot:

plot

However, I want to get a similar plot using ggplot2

Any ideas about the code?

You can check out geom_pointrange(), https://ggplot2.tidyverse.org/reference/geom_linerange.html.

I tried it before without success. I want help with the code.

Are you able to share any data?

I give my model code above. It would be helpful to me to see how the code is developed using my variables. I have used ggplots2before with continuous variables but not binomial.

The data referenced in the glmer() code you provided lists data = test. Can you provide the test data set, or a representative subset?

Here's an example on example data (as I dont have your data)


library(HSAUR3) # for example data 
library(lme4)
library(ggeffects)
library(ggplot2)

  gm2 <- glmer(outcome~treatment*visit+(1|patientID),
               data=toenail,
               family=binomial,nAGQ=20)

(step_1 <- ggpredict(gm2, terms = c("treatment", "visit")))

  # the way you get it from ggeffects
  plot(step_1)
  
  #what does step_1 look like without the ggeffects print formatting ?
  data.frame(step_1)
  
  # doing it more manually 
  ggplot(data=step_1)+
    aes(x=x,
        color=group,
        y=predicted,
        ymin=conf.low,
        ymax=conf.high) +
    geom_pointrange(position = position_jitterdodge())
2 Likes

Thank you. This seems OK.

What if I want to create a plot with more variables like the figure below using ggplots2? (you can see the names of the variable levels in the figure)

Thats a facet_wrap (or facet_grid)

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.