The answer to your first question is to use coord_cartesian(ylim=c(0,1)) instead of ylim(0,1) ; these are moderately frequently asked questions.
For your second question, there might be a way to do this in ggplot, but it was easier for me to summarize the data from the outside:
g0 <- ggplot(data = plot.data, aes(x = mean, y = response)) + geom_point() + stat_smooth(method = "loess") + facet_wrap( ~ class + sex, scale = "free") + coord_cartesian(ylim=c(0,1))+ labs(x="Predicted Probability of Survival", y="Empirical Survival Rate")
(I cut your code a bit by excluding some defaults and using labs .)
ss <- ddply(plot.data,c("class","sex"),summarise,minx=min(mean),maxx=max(mean)) g0 + geom_segment(data=ss,aes(x=minx,y=minx,xend=maxx,yend=maxx), colour="red",alpha=0.5)
source share