Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extracting RColorBrewer palette for other use

Tags:

r

ggplot2

I am using RColorBrewer (palette = "Set2"). I would like to extract the list of colors and use them for annotations. Is there a way to extract a vector of Set2 colors (call it List) and use that to make an annotation match the color already in use (color=List(3))?

Thank you.

like image 363
Paul M Avatar asked Apr 22 '15 22:04

Paul M


1 Answers

You can extract the colors like this

library(RColorBrewer)
f <- function(pal) brewer.pal(brewer.pal.info[pal, "maxcolors"], pal)
(cols <- f("Set1"))
# [1] "#E41A1C" "#377EB8" "#4DAF4A" "#984EA3" "#FF7F00" "#FFFF33" "#A65628" "#F781BF" "#999999"
like image 70
lukeA Avatar answered Oct 12 '22 07:10

lukeA