0

Hi I am trying to make this graph display the number of the count for each bar above it

sumrc<-ggplot(subset(longdata,!is.na(summresolution)), 
          aes(x=summresolution, fill=summresolution))
sumrcbycount <- sumrc + 
geom_bar(stat = "count") + 
coord_flip() +
scale_fill_brewer(palette="Paired")+
theme(axis.title.x=element_blank(),axis.title.y=element_blank(),legend.title = element_blank(),legend.position = 'none')  

i feel like i should be using geom_text() but honestly have no idea what to do, all the examples seem to be using stat= identity. I am new to R so please be very thorough in your explanation.

edit* here is a piece of the vector i'm building the graph from, the overall data set is massive, so this should suffice.

summresolution = c("Resolved by current supplier", "Resolved by current supplier", 
"Resolved by current supplier", "Supplier educated", "Beneficiary Educated", 
"Supplier educated", "Beneficiary Educated", "Beneficiary Educated", 
"Beneficiary Educated", "Beneficiary Educated", "Beneficiary Educated", 
"Unresolved", "Unresolved", "Beneficiary Educated", "Resolved by current supplier", 
"Resolved by current supplier", "Beneficiary Educated", "Beneficiary Educated", 
"New supplier Found", "Beneficiary Educated")   
  • I mean thats basically saying the only way to add data labels to my data is by creating a new table, and building the graph from that, i already have the graph i want in place, is there really no easy way to add the label?? that seems really stupid if there isnt – Travers Woodward Sep 14 '17 at 00:41
  • 1
    Please make your question reproducible by adding a data source. You can do that with `dput(longdata)` – acylam Sep 14 '17 at 00:43
  • @TraversWoodward Here is another [link](https://stackoverflow.com/questions/26553526/how-to-add-frequency-count-labels-to-the-bars-in-a-bar-graph-using-ggplot2) which likely does what you want. However, you may need to set `stat = 'count'`. The first [link](https://stackoverflow.com/questions/6455088/how-to-put-labels-over-geom-bar-in-r-with-ggplot2) I was able solve with `ggplot(df, aes(x=x, fill = x)) + geom_bar() + geom_text(stat = 'count', aes(label = ..count..), vjust = 0)` – steveb Sep 14 '17 at 00:59
  • 2
    "... that seems really stupid if there isnt" @TraversWoodward, you should be grateful to the R community for providing help for "FREE". Assuming, there isn't a solution to what you seek, why don't you "contribute" something! Asking for help and then cursing the same institution isn't quite right! – mnm Sep 14 '17 at 00:59
  • 1
    @TraversWoodward Please see [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – steveb Sep 14 '17 at 01:04
  • Im not cursing the community, I love you guys!! just really frustrated that this isn't as simple as i figured it would be considering its two button presses in excel. I'm sorry if it came across that way @Ashish , ive been working all day and its getting late here haha – Travers Woodward Sep 14 '17 at 01:11
  • 1
    @TraversWoodward Understood, but I think the other link I provided may answer your question. – steveb Sep 14 '17 at 01:22
  • It worked @steveb post it as an answer and ill give you credit!!! – Travers Woodward Sep 14 '17 at 01:31

0 Answers0