簡體   English   中英

為ggplot2中的頻率圖創建數據標簽?

[英]Create data labels for frequency plot in ggplot2?

這個問題中,可以使用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()

現在如何獲得圖中每個單獨條形的數據標簽?

謝謝。

您可以添加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))

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM