【发布时间】:2014-03-16 21:08:39
【问题描述】:
我尝试用每张图表的平均值来标记我的图表:
ggplot(diamonds, aes(x = carat, fill=cut)) +
stat_density(aes(ymax = ..density.., ymin = -..density..),
geom = "ribbon", position = "identity") +
facet_grid(. ~ cut) +
xlim(0,2.5) +
geom_text(data = NULL, x = 0.6, y = 0, label = mean(carat), size=5) +
coord_flip()
例如,这里我希望“Fair”的图表显示“Fair”的平均值,“Good”的图表显示“Good”的平均值等。
另外,但这是额外的,如果平均值为 1.0,我希望相对于 x 定位,而平均值显示在 x = 1.0
【问题讨论】:
标签: r annotations ggplot2 mean