I need to add the confidence interval to my line plot. Usually I would do this in ggplot with geom_ribbon, however I had to calculate the predictions myself from the output of my regression model. Hence it ended up in a regular base plot. Is there any way to add a confidence interval for the values p1, p2, p3 and p4?
Or as an alternative, is there any way to create a ggplot with confidence intervals from this? The items P1 to P4 are "values" in my Rstudio global environment. I have added a picture of what the plot looks like now as a reference for if it is reproducible in ggplot.
deficit <- seq(from= 0, to= 300, by= 10)
xbeta <- deficit*(-0.005104)
logistic_cdf <-function(x){
return(1/(1+exp(-x)))
}
p1 <- logistic_cdf(-1.2578 - xbeta) #none
p2 <- logistic_cdf(-0.5250 - xbeta) - logistic_cdf(-1.2578 - xbeta) #low
p3 <- logistic_cdf(0.6878 - xbeta) -logistic_cdf(-0.5250 - xbeta) #high
p4 <- 1 - logistic_cdf(0.6878 - xbeta) #very high
plot(deficit, p1, type='l',
ylab='Probabilty of nuisance level',
xlab= "Precipitation deficit",
main= "(b)",
lwd=2.5, col= "#ffd47f",
ylim = c(0.15, 0.55))
lines(deficit, p2, col='#fbfb7c', lwd=2.5)
lines(deficit, p3, col="#cfe7ef", lwd=2.5)
lines(deficit, p4, col='#75a5e9', lwd=2.5)
legend("topleft", title = "Nuisance levels", lty=1, lwd=2, col=c("#ffd47f", '#fbfb7c', "#cfe7ef", '#75a5e9'),
legend=c("No nuisance", "Low nuisance levels", "High nuisance levels", "Very high Nuisance levels"))