如何将标签添加到显示数量(而不是比例)的比例条形图中?
How can I add labels to proportion barplot showing the amount (not the proportion)?
我创建了一个比例条形图:
df <- data.frame(speech = c("figurative", "literal", "figurative", "literal"),
meaning = c("kill", "seek", "seek", "kill"),
amount = c(47, 2260, 588, 5639))
ggplot(df, aes(x=speech,y=amount, fill=meaning, group = meaning)) + geom_bar(stat = "identity", position="fill")
如何添加显示数量(而不是比例)的标签?
这是你的意思吗?根据 amount.
的值添加标签
df <- data.frame(speech = c("figurative", "literal", "figurative", "literal"),
meaning = c("kill", "seek", "seek", "kill"),
amount = c(47, 2260, 588, 5639))
ggplot(df, aes(x=speech,y=amount, fill=meaning, group = meaning)) +
geom_bar(stat = "identity", position="fill") +
geom_text(aes(label = amount), position = position_fill(vjust = 0.5))
我创建了一个比例条形图:
df <- data.frame(speech = c("figurative", "literal", "figurative", "literal"),
meaning = c("kill", "seek", "seek", "kill"),
amount = c(47, 2260, 588, 5639))
ggplot(df, aes(x=speech,y=amount, fill=meaning, group = meaning)) + geom_bar(stat = "identity", position="fill")
如何添加显示数量(而不是比例)的标签?
这是你的意思吗?根据 amount.
的值添加标签df <- data.frame(speech = c("figurative", "literal", "figurative", "literal"),
meaning = c("kill", "seek", "seek", "kill"),
amount = c(47, 2260, 588, 5639))
ggplot(df, aes(x=speech,y=amount, fill=meaning, group = meaning)) +
geom_bar(stat = "identity", position="fill") +
geom_text(aes(label = amount), position = position_fill(vjust = 0.5))