I need to apply cut
on a continuous variable to show it with a Brewer color scale in ggplot2, as in Setting breakpoints for data with scale_fill_brewer() function in ggplot2. The continuous variable is a relative difference, and I'd like to format the data as "18.2 %" instead of "0.182". Is there an easy way to achieve this?
x <- runif(100)
levels(cut(x, breaks=10))
[1] "(0.0223,0.12]" "(0.12,0.218]" "(0.218,0.315]" "(0.315,0.413]"
[5] "(0.413,0.511]" "(0.511,0.608]" "(0.608,0.706]" "(0.706,0.804]"
[9] "(0.804,0.901]" "(0.901,0.999]"
I'd like, e.g., the first level to appear as (2.23 %, 12 %]
. Is there a better alternative to cut
?