标签: r ggplot2
在this问题中,可以使用ggplot创建频率数字。例如:
f <- factor(sample(letters[1:5], 100, r=T)) h <- table(f) / length(f) dat <- data.frame(f = f) ggplot(dat, aes(x=f, y=..count.. / sum(..count..), fill=f)) + geom_bar()
我现在如何获取图中每个条形的数据标签?
谢谢。
答案 0 :(得分:2)
您可以添加geom_text():
geom_text()
library(ggplot2) ggplot(dat, aes(x=f, y=..count.. / sum(..count..), fill=f)) + geom_bar() + geom_text(stat = "count", aes(label=..count../100))