Graph with binned gradient and intervals shown in the legend

Hi all!

Let's say I want to make a graph where I want a binned gradient with specific breaks. This can be achieved using scale_color_steps, e.g.

set.seed(4020)
df <- data.frame(
  x = runif(100),
  y = runif(100),
  z1 = rnorm(100)
)

# Use scale_colour_steps for a standard binned gradient
library(tidyverse)
ggplot(df, aes(x, y)) +
  geom_point(aes(colour = z1)) +
  scale_colour_steps(breaks = c(-.5, 0, .5),
                     low = "white", high = "darkblue")

Created on 2022-03-25 by the reprex package (v2.0.1)

But if I want the legend to show the intervals associated with each color instead of the values for each break, can this be achieved in some easy way? Or do I have to first create a new variable with the categories I want for Z1?

Any help would be greatly appreciated!
Best, R

Thats the way I would approach it. :+1:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.