It looks like this has been asked before, and I failed initially to see how they connected. I'm answering this here, but leaving it as not accepted in case someone has something more elegant. Also, the n = foo is a common enough case, that hopefully someone will get some use out of this question even though it's a bit duplicative.
require(ggplot2)
require(plyr)
mms <- data.frame(deliciousness = rnorm(100),
type=sample(as.factor(c("peanut", "regular")),
100, replace=TRUE),
color=sample(as.factor(c("red", "green", "yellow", "brown")),
100, replace=TRUE))
mms.cor <- ddply(.data=mms,
.(type, color),
summarize,
n=paste("n =", length(deliciousness)))
plot <- ggplot(data=mms, aes(x=deliciousness)) +
geom_density() +
facet_grid(type ~ color) +
geom_text(data=mms.cor, aes(x=1.8, y=5, label=n),
colour="black", inherit.aes=FALSE, parse=FALSE)
plot
