我想将相应的值标签geom_col
放置在每个条形段中间的堆叠条形图中。
然而,我天真的尝试失败了。
library(ggplot2) # Version: ggplot2 2.2
dta <- data.frame(group = c("A","A","A",
"B","B","B"),
sector = c("x","y","z",
"x","y","z"),
value = c(10,20,70,
30,20,50))
ggplot(data = dta) +
geom_col(aes(x = group, y = value, fill = sector)) +
geom_text(position="stack",
aes(x = group, y = value, label = value))
显然,设置y=value/2
forgeom_text
也无济于事。此外,文本的位置错误(反转)。
任何(优雅的)想法如何解决这个问题?