Add label names on the color bar manually using ggplot2 package

Hi, please help me :slight_smile:
I want to add manual label names on the color bar just like this --- labels = c("Low", 5, 10, 25, 60, "High"). In simple, I want to add text for Low and High values at the bottom and top of the scale bar (at the side of 0 and 100). How can I add this? Please, help me :slight_smile:

x <- 1:100
y <- runif(100) * 100
tib <- tibble(x, y)

ggplot(tib, aes(x = x, y = y, color = y)) +
  geom_point() +
  binned_scale(aesthetics = "color",
               scale_name = "stepsn", 
               palette = function(x) c("red", "yellow", "green", "yellow", "red"),
               breaks = c(0, 5, 10, 25, 60, 100),
               limits = c(0, 100),
               show.limits = TRUE, 
               guide = "colorsteps"

Like this---

I tried to adding--- labels = c("Low", 5, 10, 25, 60, "High") in the script but it showed the error====
Error in f():
! Breaks and labels are different lengths
Run rlang::last_error() to see where the error occurred.

1 Like

Hi @SPratap , Im find the same quenstion but other user. This is the solution.

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.