【发布时间】:2018-01-02 12:42:28
【问题描述】:
我正在使用以下代码生成柱状图:
library(ggplot2)
set.seed(123)
dt <- data.frame(SurveyDate = sample(1:500, 1000, replace = TRUE))
ggplot(dt, aes(SurveyDate)) + stat_bin(bins = 50) + ylab('Survey Responses')
我想在上面加一条黄土线,但是这段代码:
ggplot(dt, aes(SurveyDate)) + stat_bin(bins = 50) + ylab('Survey Responses') +
stat_smooth(aes(SurveyDate, ..count..), method='loess')
给我一个错误:stat_smooth requires the following missing aesthetics: y
如何从 stat_smooth 中访问 stat_bin 的 y 值?
【问题讨论】:
-
你能提供一个可重现的例子吗?