StatisticsNZ / simplevis

Simple visualisation with ggplot2 and leaflet wrappers
https://StatisticsNZ.github.io/simplevis
Other
86 stars 11 forks source link

cut: change kimisc::cut_format to santoku::chop #425

Closed davidhodge931 closed 2 years ago

davidhodge931 commented 2 years ago

Alternative to kimisc::cut_format would be santoku::chop https://hughjonesd.github.io/santoku/

library(santoku)
library(kimisc)`

set.seed(20200607)
x <- runif(20)

chop(x, seq(0, 1, 0.2), 
     labels = lbl_intervals(fmt = scales::label_percent(accuracy = 0.1)))

chop(x, seq(0, 1, 0.2), 
     labels = lbl_intervals(fmt = function(x) paste(x, ":)")))

chop(x, seq(0, 1, 0.2), 
     labels = lbl_intervals(fmt = ~ paste(.x, ":)")))

cut_format(x, seq(0, 1, 0.2), 
     format_fun = function(x) paste(x, ":)"))

cut_format(x, seq(0, 1, 0.2), 
           format_fun = scales::label_percent())
davidhodge931 commented 2 years ago
library(kimisc)
library(santoku)

chop(runif(10), 
     breaks = seq(0, 1, by = 0.25), 
     labels = lbl_intervals(fmt = scales::label_dollar()), 
     left = TRUE, 
     close_end = TRUE, 
     drop = FALSE)

cut_format(runif(10), seq(0, 1, by = 0.25), 
           format_fun = scales::label_dollar(), 
           right = FALSE, 
           include.lowest = TRUE)
davidhodge931 commented 2 years ago

For use in chop functions, you'll need to:

col_intervals_left <- ifelse(col_intervals_right == TRUE, FALSE, TRUE)