Closed
Description
The idea behind exposing a palette to discrete position scales is that the palette can be used to set custom spacings between discrete variables. Currently the 'palette' of discrete position scales is essentially seq_along()
, and the ask here is to open this up to other functions that can translate discrete variables to continuous positions.
To give an example, let's say I have the following plot with a fake continuous scale separating groups of clarity:
library(ggplot2)
clarity_position <- function(x) {
as.integer(x) + c(0, 1, 1, 2, 2, 3, 3, 4)[match(x, levels(x))]
}
ggplot(diamonds, aes(clarity_position(clarity), price, group = clarity)) +
geom_boxplot() +
scale_x_continuous(
breaks = c(1, 3, 4, 6, 7, 9, 10, 12),
labels = levels(diamonds$clarity)
)
Created on 2024-03-12 with reprex v2.1.0
I'd like to express a similar plot in the following way:
ggplot(diamonds, aes(clarity, price)) +
geom_boxplot() +
scale_x_discrete(
palette = \(x) c(1, 3, 4, 6, 7, 9, 10, 12)
)
I'd imagine it just uses the discrete expansion rules and not show minor breaks in the panel grid.