I have several binary data, and I want to build a logistic regression line and a histogram of the relative frequencies 0s and 1s in the same section.
I came across a very good implementation using the popbio package here: shizuka lab page
Here's the MWE that works with the library (popbio) (courtesy of shizuka lab)
bodysize=rnorm(20,30,2) # generates 20 values, with mean of 30 & sd=2 bodysize=sort(bodysize) # sorts these values in ascending order. survive=c(0,0,0,0,0,1,0,1,0,0,1,1,0,1,1,1,0,1,1,1) # assign 'survival' to these 20 individuals non-randomly... most mortality occurs at smaller body size dat=as.data.frame(cbind(bodysize,survive)) #and now the plot library(popbio) logi.hist.plot(bodysize,survive,boxp=FALSE,type="hist",col="gray")
which produces

Now, can this be done with ggplot2?
source share