# NOT RUN {
x <- cut(-1:5, 3, right = FALSE)
y <- cut(-4:10, c(-5, 2, 6, 10), right = TRUE)
z <- cut(-4:10, c(-4, 2, 6, 11), right = FALSE)
f_bin(x)
f_interval(x) #`_interval` and `_bin` are interchangeable aliases in the function names
f_bin(y)
f_bin(z)
## HTML
f_bin(z, le = '≤')
f_bin_text(x)
f_bin_text(y)
f_bin_text(z)
f_bin_text(x, middle = 'but')
f_bin_text(x, greater = 'Above', middle = '', equal = '', less = 'to')
f_bin_text(z, greater = 'From', middle = '', equal = '', less = 'up to')
f_bin_text_right(x)
f_bin_text_right(y)
f_bin_text_right(cut(-4:10, c(-3, 2, 6, 11)))
f_bin_text_right(x, equal.digits = TRUE)
f_bin_right(x)
f_bin_right(y)
f_bin_right(x, equal.digits = TRUE)
## HTML
f_bin_right(y, le = '≤')
# }
# NOT RUN {
library(tidyverse)
mtcars %>%
mutate(mpg2 = cut(mpg, 3)) %>%
ggplot(aes(disp, hp)) +
geom_point() +
facet_wrap(~ mpg2,
labeller = ff_bin()
)
mtcars %>%
mutate(mpg2 = cut(mpg, 3)) %>%
ggplot(aes(disp, hp)) +
geom_point() +
facet_wrap(~ mpg2,
labeller = function(x) f_bin_right(x, parse = TRUE)
)
mtcars %>%
mutate(mpg2 = cut(mpg, 3, right = FALSE)) %>%
ggplot(aes(disp, hp)) +
geom_point() +
facet_wrap(~ mpg2,
labeller = function(x) f_bin_right(x, parse = TRUE)
)
mtcars %>%
mutate(mpg2 = cut(mpg, 5, right = FALSE)) %>%
ggplot(aes(mpg2)) +
geom_bar() +
scale_x_discrete(labels = ff_bin_text_right(l = 'Up to')) +
coord_flip()
mtcars %>%
mutate(mpg2 = cut(mpg, 10, right = FALSE)) %>%
ggplot(aes(mpg2)) +
geom_bar(fill = '#33A1DE') +
scale_x_discrete(labels = function(x) f_wrap(f_bin_text_right(x, l = 'up to'), width = 8)) +
scale_y_continuous(breaks = seq(0, 14, by = 2), limits = c(0, 7)) +
theme_minimal() +
theme(
panel.grid.major.x = element_blank(),
axis.text.x = element_text(size = 14, margin = margin(t = -12)),
axis.text.y = element_text(size = 14),
plot.title = element_text(hjust = .5)
) +
labs(title = 'Histogram', x = NULL, y = NULL)
# }
Run the code above in your browser using DataLab