I am trying to add data label on a histogram but would like to see limited decimal. Current code is as below:
label = after_stat(scales::percent(cumsum((count / sum(count))))))
It works fine, but returns different number of decimals depending chart variable data plotted.
Then I referred this link: how to put exact number of decimal places on label ggplot bar chart and modified code as below:
label = after_stat(sprintf("%0.f",round(scales::percent(cumsum((count / sum(count)))),digits=2)))
Error in round(scales::percent(cumsum((count/sum(count))))) : non-numeric argument to mathematical function
Can you please suggest right way to trim/round decimal to say 2 places?. Thanks.