I am trying to get a vline on a predicted plot until the sjplot::plot_model function. I have a paneled graph and for each condition (baseline, autonomous and fairness) I have a different vline I want to depict. Basically the point of divergence when the CI bands no longer overlap.
The issue I have is that I can get the lines on there, but it's all three lines for each panel rather than a unique line for each panel.
Here is the code I use to create my model
model3 <- glmer (reject ~ (1|sn) + condition*dist*actor.age.years +
block + actor.gender,
data = en.long.ai, family = binomial,
nAGQ = 1,
control = glmerControl(optimizer = "optimx", optCtrl = list(method = "bobyqa")))
then I do this to create my plot
ai.pred.plot <- sjPlot::plot_model(model3, type = "pred", terms = c( "actor.age.years", "dist", "condition"), title = "AI: Predicted probability of rejections",
se = TRUE,
legend.title = "allocation type",
show.data = F,
colors = "Set2")
print (ai.pred.plot + labs(y = "Probability of rejection") + labs(x = "Age (years)"))
Here is what I get. predicted plot of rejections by condition and age
Then I try to make the vline. I've tried many methods....
#create a data frame
#one attempt
Primary<- c(6.6, 7.4, 4.75 )
grid <- c("Basline", "Autonomous", "Fairness")
treat<- data.frame(grid, Primary,stringsAsFactors = F)
#another attempt
vline.data <- data.frame(z = 6.6, 7.2, 4.5), condition = c("Baseline","Autonomous","Fariness"))
vline.data <- data.frame(condition = ("Baseline", z = 6.6), ("Autonomous", z = 7.2), ("Fariness", z = 7.2))
# then I try to add it to the plot
ai.pred.plot + geom_vline(aes(xintercept = z), vline.data, linetype = "dashed", color = "grey30") +
guides(fill = FALSE)
#or
print (ai.pred.plot + geom_vline(data=treat,aes(xintercept = Primary), linetype = "dotdash") )
I always get this.
but I want one line per panel.
please help.