您必须创建另一个汇总表(每年的频率总和),并将其添加到另一个绘图中。
geom_text
层带
vjust
>1在酒吧上方。
dfSum <- aggregate(Data$Frequency, list(Data$Year), sum)
ggplot(Data, aes(Year, Frequency, fill = Category, label = Frequency)) +
geom_bar(stat = "identity") +
geom_text(size = 3, position = position_stack(vjust = 0.5)) +
geom_text(aes(Group.1, x, label = x), dfSum, inherit.aes = FALSE,
position = position_stack(vjust = 1.05))