[R] How to use RColorBrewer in ggplot2?

Luigi Marongiu m@rong|u@|u|g| @end|ng |rom gm@||@com
Thu Aug 14 07:25:20 CEST 2025


Hello,
I would like to define a color range to custom color some plot,
specifically made in ggplot2 (but also for normal plots).
I have been trying to use RColorBrewer but I don't get any value out
of this function. I expected it would create a vector of color values,
but I must be missing something.
What is the correct you of this function?
Thank you.

EXAMPLE
```
set.seed(50)
df = data.frame(x = runif(15, 0, 1),
                y = x^2 + runif(15, 0, 1),
                z = rep(1:5, 3))
library(ggplot2)
library(RColorBrewer)
ggplot(df, aes(x=x, y=y, colour=z, group=z)) +
  geom_point(size=4) +
  scale_fill_brewer(palette = "Paired")
```


-- 
Best regards,
Luigi



More information about the R-help mailing list