This is what I think you may want (to show the differences in mean IQ value superimposed on the boxplot):
plot(IQ~isAtheist)
lines(x=c(1,2), y=predict( lm(IQ~isAtheist),
newdata=list(isAtheist=c("NO","YES") ) ) ,
col="red", type="b")
The X-position in the default of plot.formula is as.numeric(factor(isAtheist))
, i.e. at 1 and 2 rather than at 0 and 1 which was what you were assuming with your use of abline
. Makes no sense to extrapolate beyond those values, so I chose to plot as a bounded segment. I will add a worked example and output.
set.seed(123)
isAtheist=factor(c("NO","YES")[1+rep( c(0,1), 50 )])
plot(IQ~isAtheist)
lines(x=c(1,2), y=predict( lm(IQ~isAtheist),
newdata=data.frame(isAtheist=c("NO","YES") ) ) ,
col="red", type="b")
