在ggplot中使用annotate函数来替代bgroup。
示例代码:
library(ggplot2)
df <- data.frame(x = c("A", "B", "C"), y = c(10, 20, 30))
ggplot(df, aes(x, y)) + geom_bar(stat = "identity") + bgroup("Total")
ggplot(df, aes(x, y)) + geom_bar(stat = "identity") + annotate("text", x = 2, y = 35, label = "Total")