Select individual colors from the RColorBrewer palette as scale_colour_manual () in ggplot2

Using scale_colour_manual() , can I select specific colors from RColorBrewer to use as color values?

For example, in:

 scale_colour_manual(breaks=c("A","B","C","D","E"), values=c("green","orange","blue","pink","yellow")) 

I would like to use the first color from the scale_colour_brewer(type = "qual", palette = 7) palette scale_colour_brewer(type = "qual", palette = 7) instead of "green", then the fourth color from the scale_colour_brewer(type = "qual", palette = 2) palette scale_colour_brewer(type = "qual", palette = 2) instead of "orange", etc.

+5
source share
1 answer

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 
+17
source

Source: https://habr.com/ru/post/1204368/


All Articles