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
Select the decimal number cells, and then click Home > % to change the decimal numbers to percentage format. 7. Then go to the stacked column, and select the label you want to show as percentage, then type = in the formula bar and select percentage cell, and press Enter key. 8.
Goto “Chart Design” >> “Add Chart Element” >> “Data Labels” >> “Center”. You can see all your chart data are in Columns stacked bar. Step 5: Steps to add percentages/custom values in Chart. Create a percentage table for your chart data.
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With