How to display a percentage mark on top of each row

I am new to RI using ggplot to display a barcode graph. I want to display the percentage of the top of each bar. I do not want to convert the y axis to a percentage mark. I want to display the frequency in the y-axis and the percentage of each group on top of the bar.

My piece of data

And my desired output

Any hints are welcome

+6
source share
1 answer

This kind of plot can be easily created using 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

+7
source

Source: https://habr.com/ru/post/947620/


All Articles