As mentioned above, your ddply call seems off to me - I think it always yields the same ratio (over the whole dataframe). I could not figure out a compact elegant one from the top of my head so I had to resort to a somewhat clunky one but it does work.
EDIT: I changed the code to reflect the workaround described by http://rwiki.sciviews.org/doku.php?id=tips:graphics-ggplot2:aligntwoplots to adress the OP's comment.
#sample data
test=data.frame(gender=c("m","m","f","m","f","f","f"),age=c(1,3,4,4,3,4,4))
require(plyr)
age_N <- ddply(test, c("age","gender"), summarise, N=length(gender))
require(reshape2)
ratio_df <- dcast(age_N, age ~ gender, value.var="N", fill=0)
ratio_df$ratio <- ratio_df$m / (ratio_df$f+ratio_df$m)
#create variables for facetting
test$panel = rep("Distribution",length(test$gender))
ratio_df$panel = rep("Ratio",length(ratio_df$ratio))
test$panel <- factor(test$panel,levels=c("Ratio","Distribution"))
require(ggplot2)
g <- ggplot(data = test, aes(x = factor(age)))
g <- g + facet_wrap(~panel,scale="free",ncol=1)
g <- g + geom_line(data = ratio_df, aes(x = factor(age), y = ratio, group=1))
g <- g + geom_bar(aes(fill=gender))
print(g)
Is this what you are looking for? However, I think @SvenHohenstein is right that the line does not any information as the split is evident form the fill.
