-3

I have a bar chart with values as lables on the bars.
How can I add values from another column in the dataframe on top or along side the current lables.
enter image description here The dataframe has 3 groups, counts and proportions. I want to add counts column to the lables. I hope to avoid having to merge the 2 columns into a string column.
Here is the code:

group <- c('group1','group2','group3')
count <- c(10,20,15)
prop <- c(.22,.44,.34)
data.frame(cbind(group,count,prop)) %>% 
  ggplot(aes(x=group, y = prop)) + 
  geom_col()+
  geom_text(aes(label = prop),position = position_dodge(width = 0.9), vjust=1, cex =5, col = 'white')

This is different to another question posted here because I want to know how to add additional value to the bar chart not just replace what I have.

jmich738
  • 1,565
  • 3
  • 24
  • 41
  • Possible duplicate of [Show % instead of counts in charts of categorical variables](https://stackoverflow.com/questions/3695497/show-instead-of-counts-in-charts-of-categorical-variables) – Maurits Evers Mar 13 '18 at 00:44
  • @jmich: Do more searching next time. – IRTFM Mar 13 '18 at 00:57
  • 1
    @42 could you please explain why you would think that I did not search for answers before? The link provided my Mourits Ever clearly has a title which is very different to what I was looking for. I specifically wanted to show multiple values not one instead of the other. As far as I saw, I could not find any question that directly related to what I needed. And there is no way I'm going to read through all the posts that 'might' contain the answer somewhere down all the comments and proposed solutions when the main question is not what I wanted. – jmich738 Mar 13 '18 at 02:08
  • The reason that I think that is my prior experience suggests to me that very few people do searching. (And it still looks like a duplicate anyway.) If you do searching and don't find anything, the best way to avoid that presumption is to show what you found and say why it's not answering your question. I'm now wondering why you didn't search for methods of `annotate`? – IRTFM Mar 13 '18 at 17:50
  • @42 Look, I don't want to get into argument with you on this. The definition of "doing your research" seems to be different for each site monitor. I would say that I've as much reseach as I thought was required given the problem and the solutions to other similar problems I found. Why didn't I search for methods on `annotate`? Because I don't know enough about this package to link the 2 together. That's why I'm asking. – jmich738 Mar 13 '18 at 23:19
  • I'm not a site monitor. I lack the patience. I would refer you to [Ask] and note the material (near the top) where it asks you to post the results of any searching you have done. – IRTFM Mar 14 '18 at 06:26

1 Answers1

1

You could just add another geom_text layer

group <- c('group1','group2','group3')
count <- c(10,20,15)
prop <- c(.22,.44,.34)
data.frame(cbind(group,count,prop)) %>% 
  ggplot(aes(x=group, y = prop)) + 
  geom_col()+
  geom_text(aes(label = prop),position = position_dodge(width = 0.9),
            vjust=1, cex =5, col = 'white') +
  geom_text(aes(label = count), position = position_dodge(width = 0.9),
            vjust = 3, cex = 5, col = "white")

Although it's getting confusing with multiple labels on top of each other like that

enter image description here

Conor Neilson
  • 1,026
  • 1
  • 11
  • 27