ggplot2 icon indicating copy to clipboard operation
ggplot2 copied to clipboard

Give `midpoint` argument to gradient scales

Open teunbrand opened this issue 3 months ago • 0 comments

This PR aims to fix #3738.

In short, it adds a midpoint argument to scale_{fill/colour}_gradientn() and scale_{fill/colour}_stepsn() functions.

The approach somewhat diverges from the gradient2/steps2 variant, which will not accept rescaler arguments. The gradientn/stepsn variants will accept a rescaler, but it overrides any midpoint setting.

Reprex:

devtools::load_all("~/packages/ggplot2")
#> ℹ Loading ggplot2

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

p + scale_colour_gradientn(
  colours = c("purple", "white", "green"),
  midpoint = 15
)


p + scale_colour_stepsn(
  colours = c("purple", "white", "green"),
  midpoint = 15
)

Created on 2024-04-03 with reprex v2.1.0

teunbrand avatar Apr 03 '24 14:04 teunbrand