I have a dataset with 142 observations about probability of individual crossing (nRF01) by different width gap (LargDiscon) at four sites (Site), like that :
LargDiscon nRF01 Site
1 90 0 Azay-sur-Thouet
2 79 0 Azay-sur-Thouet
3 55 0 Azay-sur-Thouet
4 125 0 Azay-sur-Thouet
5 40 0 Azay-sur-Thouet
6 28 0 Azay-sur-Thouet
I performed a GLM with a binomial error distribution with width gap, site (colored slopes in the plot) and interaction between the two as explanatory variables. I also need the model overall (black slope in the plot) because we used this model for an other analysis.
gt <- glm(nRF01 ~ LargDiscon*Site, data=p, family="binomial") #model with four sites
gt2 <- glm(nRF01 ~ LargDiscon, data=p, family="binomial") #model overall
After that, I plot the model with sites but I also added the overall slope with this following code :
# Plot
par(cex=0.8, cex.lab = 1.5, cex.sub=1) # increase size font
par(cex.lab=1.7, cex.axis=1.9, cex.main=1.9,
mar = c(5, 5, 5, 5))
plot(jitter(nRF01, 0.1) ~ LargDiscon,
data=p, t="n",
xlim=c(0, 170),
xaxs="i",
ylim=c(-0.05, 1.05),
xlab="Gap width (m)",
ylab="Probability of crossing",
main=" ")
lg <- seq(1, 170, 1)
nd <- data.frame(LargDiscon=rep(lg,times=4), Site=rep(levels(p$Site), each=length(lg))) #predictions
nd$pred <- as.vector(predict(gt, nd, type="response")) # using model to predict values of points
pred <- as.vector(predict(gt2, list(LargDiscon=lg), type="response")) #pred of overall model
# add confidence interval
# how ?
abline(h=c(0,1), col="darkgrey")
abline(v=0, col="darkgrey")
col <- c("#FF6101", "#D90000", "#0093A5", "#902E98")
lty <- c("dotted", "dotdash", "twodash", "longdash")
for(i in 1:4) {
points(pred ~ LargDiscon, data=nd[nd$Site==levels(p$Site)[i], ],
lwd=2,
col=col[i],
lty = lty[i],
t="l")
}
points(lg, pred, lwd=2, col="black", t="l")
points(jitter(nRF01, 0.08) ~ LargDiscon, data=p, pch=20, bg="black", col = c("#FF6101", "#D90000", "#0093A5", "#902E98"))
abline(h=0.5, col="darkgrey", lty=2)
But I really need to add confident interval for each model, and I failed. I try with ggplot but I failed too. Could someone help me add the confidence intervals to this graph?

I succeeded with ggplot. I've included the script below. This allows you to have your model + the overall model on the same graph.