可能重复:
创建与每个情节不同的注释GGPLOT2一个facet_wrap阴谋
在GGPLOT2添加文本层面的情节与X轴日期
小面在ggplot数据偶尔的时候,我认为这将是很好的注释与落入每个方面意见的数量每个方面。 小面可能会导致每面相对一些意见时,这一点尤为重要。
什么是添加一个“N = X”这个情节的每个方面的最佳/最简单的方法是什么?
require(ggplot2)
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))
plot <- ggplot(data=mms, aes(x=deliciousness)) + geom_density() + facet_grid(type ~ color)
看起来这之前已经问过了,我没有最初看到他们是如何连接的。 我在这里回答这个问题,而是把它当作不万一有人接受了一些更优雅。 此外,N = foo是一个普通不过的情况下,希望有人会得到一些使用了这个问题,即使它是一个有点重复的。
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