tidyverse/ggplot2

Could continuous colour scale `rescaler` argument work with `\(x) x` notation?

Closed this issue · 3 comments

It'd be great if rescaler argument could work with \(x) x notation!

library(tidyverse)
library(scales)

p <- mpg  |>
  ggplot() +
  geom_point(
    aes(x = displ,
    y = hwy,
    colour = cty),
  )

#works
p +
  scale_colour_continuous(
    palette = pal_div_gradient("blue", "white", "red"),
    rescaler = ~ scales::rescale_mid(.x, mid = 15),
  ) 

#doesn't
p +
  scale_colour_continuous(
    palette = pal_div_gradient("blue", "white", "red"),
    rescaler = \(x) scales::rescale_mid(x, mid = 30),
  ) 

It works if you use \(x, ...) instead of \(x).

Ah thanks!

It feels like it'd be nicer if it could work with (x) x like other functions, if not too difficult

Feel free to close

The rescaler gets passed multiple arguments, so I don't think \(x) are appropriate formals to use for the rescaler function.