Using scale_colour_manual()
, can one pick specific colours from RColorBrewer to use as colour values?
For instance, in:
scale_colour_manual(breaks=c("A","B","C","D","E"),
values=c("green","orange","blue","pink","yellow"))
I'd like to use the first colour from the palette scale_colour_brewer(type = "qual", palette = 7)
instead of "green", then the fourth colour of the palette scale_colour_brewer(type = "qual", palette = 2)
instead of "orange", and so on.
I often do the following,
library(RColorBrewer)
my_palette = c(brewer.pal(5, "Set1")[c(1,3,4,5)], brewer.pal(5, "Pastel1")[c(2,5,1,3)])
#grid::grid.raster(my_palette, int=F)
scale_colour_discrete = function(...) scale_colour_manual(..., values = palette())
dsamp <- diamonds[sample(nrow(diamonds), 1000), ]
(p <- qplot(carat, price, data = dsamp, colour = clarity)) # default palette
palette(my_palette)
p # custom colors
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With