将总直方图计数添加到R

时间:2020-08-05 17:51:00

标签: r ggplot2 histogram facet-grid

我想获取一个多面直方图,并在每幅图上添加文本,以指示该多面中的观测总数。因此,对于carb = 1,总计数为7,而carb = 2则总计数为10,依此类推。

p <- ggplot(mtcars, aes(x = mpg, stat = "count",fill=as.factor(carb))) + geom_histogram(bins = 8)
p <- p + facet_grid(as.factor(carb) ~ .)
p

我可以使用table函数来执行此操作,但是对于更复杂的方面,我该如何快速执行呢?

enter image description here

1 个答案:

答案 0 :(得分:2)

您可以尝试一下。可能不是最佳选择,因为您必须为标签定义private let link1Controller = UIStoryboard.init(name: "Main", bundle: nil).instantiateViewController(identifier: "link1ViewController") x的位置(在y的{​​{1}}和Labels中完成此操作x和3)。但这可以帮助您:

geom_text()

enter image description here