Home > Enterprise >  How can I add labels to proportion barplot showing the amount (not the proportion)?
How can I add labels to proportion barplot showing the amount (not the proportion)?

Time:10-10

I created a proportion barplot:

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")

How can I add labels showing the amount (not the proportion)?

CodePudding user response:

Is this what you mean? Adding labels based on the values for 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))

enter image description here

  • Related