Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

change decimal on y axis, geom_bar, "accuracy" not working

I would like to design a bar plot that shows the frequencies of age classes in percent on the y-axis with no decimal. I use ggplot and geom_bar. I have read many posts but I can’t remove the one decimal from the y-axis label (see pic: at the moment it is 50.0% but i want just 50%).
I tried accuracy=1, accuracy=0.01 etc., but it is not working.

I have the following code to design the bar plot:

myplot_age <- ggplot(data_new_fewmissing_out, aes(age)) + 
geom_bar(aes(y = (..count..)/sum(..count..)), fill=c("lightgreen", "blue", "black", lightblue")) + 
scale_y_continuous(labels=scales::percent) +
ylab("relative frequencies")+ 
theme(axis.title.x = element_text(size = 15),
axis.title.y = element_text(size = 15),
axis.text = element_text(size = 12, color = "black"))+
scale_x_discrete(labels=c("young", "middle", "old" ,"no answer"))

The results looks like the following

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

bar plot with one decimal

If I apply the same code to another of my variables (e.g. farm system) it gives me no decimals so I would be grateful for a solution.
Thanks!

>Solution :

use

scales::percent_format(accuracy = 1)

rather than

scales::percent

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading