如果我使用下面的代码绘制df
,我可以将每列的n放在列本身as seen in this example plot上。我想做的还是在标签中列出每列的百分比。这是该列组成的总数的百分比。因此,例如,第一列上的标签将显示为127(42.9%)
,而不仅仅是127
。我怎么能这样做?
df <- structure(list(Letter = structure(1:7,
.Label = c("A", "B", "C", "D", "E", "F", "G"),
class = "factor"), Freq = c(127L, 101L, 24L, 19L, 3L, 0L, 22L)),
.Names = c("Letter", "Freq"),
row.names = c(NA, -7L),
class = "data.frame")
ggplot(df, aes(Letter, Freq, label = Freq)) +
geom_col() +
geom_text(size = 3, position = position_dodge(width = 1), vjust = -0.25)