我使用以下代码生成直方图条形图:
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')
我想在它上面添加一个LOESS行,但是这段代码:
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值?