【发布时间】:2012-11-05 20:26:49
【问题描述】:
可能重复:
Creating a facet_wrap plot with ggplot2 with different annotations in each plot
Add text to a faceted plot in ggplot2 with dates on X axis
偶尔在 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)
【问题讨论】:
-
赞成包含图像和可重现数据(参见“创建 facet_wrap...”)