decimal places in ggplot2

Hi,

I use

scale_fill_gradientn(colours= rev(palette),labels=function(x) paste0(x, "%"),digits=1)

to add a percentage sign to a legend. Could you advise me how to set the number of decimal places legend shows?

Thank you

Jakub

Hi Jakub, this should do the job:

scale_fill_gradientn(colours= rev(palette),labels=function(x) paste0(format(round(x, 2), nsmall = 2), "%"))

Please always post a reproducible example so I can test it myself instead of speculating: https://www.jessemaegan.com/post/so-you-ve-been-asked-to-make-a-reprex/

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.