使用 ggplot 绘制独特观察结果的摘要

Plot summary of unique observations with ggplot

是否可以通过 ggplot 公式计算唯一观察值?例如,通过切断中间线以某种方式达到与此相同的结果?到目前为止我的努力使用 geom_histogram 和 stat='bin' 失败。

set.seed(1)
d = data.frame(year = sample(2005:2009, 50, prob = 1:5, rep=T), 
               group = sample(letters, 50, prob = 1:26, rep=T))
d2 = plyr::count(unique(d)$year)
ggplot(d2, aes(x, freq)) + geom_bar(stat='identity') + labs(x='year', y='count of groups')

stat_bin() 会这样做:

ggplot(unique(d), aes(x = as.factor(year))) + 
  stat_bin() + 
  labs(x='year', y='count of groups')