6

I am novice to R.I am using ggplot to display bar plot.I want to display percentage of top of every bar.I don't want to convert y-axis to percentage label.Rather i want to display frequency in y-axis and percentage of every group on top of bar.

My data Snippet is

And my desired output snippet is

Any helps are welcomed

stackoverflowuser
  • 252
  • 1
  • 3
  • 12
  • 1
    Use `geom_text` to do this, and please help us help you by providing us with a reproducible example (i.e. code and example data), see http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example for details. – Paul Hiemstra Jun 19 '13 at 07:07

1 Answers1

9

This kind of plot can be created easily with ggplot2.

dat <- data.frame(Frequency = c(10, 5, 97, 47, 50),
                  Fruits = gl(5, 1, labels = c("Mango", "Apple", "Orange", 
                                               "Guava", "Papaya")))


library(ggplot2)
ggplot(dat, aes(x = Fruits, y = Frequency)) +
  geom_bar(stat = "identity") +
  geom_text(aes(label = sprintf("%.2f%%", Frequency/sum(Frequency) * 100)), 
            vjust = -.5)

enter image description here

Sven Hohenstein
  • 80,497
  • 17
  • 145
  • 168