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 i
I have implemented cut_format() in version 0.2-3 of my kimisc
package, version 0.3 is on CRAN now.
# devtools::install_github("krlmlr/kimisc")
x <- seq(0.1, 0.9, by = 0.2)
breaks <- seq(0, 1, by = 0.25)
cut(x, breaks)
## [1] (0,0.25] (0.25,0.5] (0.25,0.5] (0.5,0.75] (0.75,1]
## Levels: (0,0.25] (0.25,0.5] (0.5,0.75] (0.75,1]
cut_format(x, breaks, format_fun = scales::percent)
## [1] (0%, 25%] (25%, 50%] (25%, 50%] (50%, 75%] (75%, 100%]
## Levels: (0%, 25%] (25%, 50%] (50%, 75%] (75%, 100%]
It's still not perfect, passing the number of breaks (as in the original example) doesn't work yet.