how can I see what colors ggplot2 is using for discrete categories using a given palette, like "Set1" or "Set2" for brewer? i.e. for a given set of categories what the colors that will be used are?
Asked
Active
Viewed 3,981 times
5
-
one way could be to look at the colours returned by `ggplot_build(p)` (where `p` is your plot) or have a look at http://stackoverflow.com/questions/8197559/emulate-ggplot2-default-color-palette, or http://stackoverflow.com/questions/6075140/in-r-how-do-i-change-the-color-value-of-just-one-value-in-ggplot2s-scale-fill-b – user20650 Mar 21 '15 at 00:01
1 Answers
8
By default it will use hue_pal
with certain defaults. When you use scale_x_brewer
it will use brewer_pal
with certain defaults (both from the scales
package). You'll get as many colors from those palettes as you have categories. e.g. (using the defaults):
f <- hue_pal(h = c(0, 360) + 15, c = 100, l = 65, h.start = 0, direction = 1)
f(3)
## [1] "#F8766D" "#00BA38" "#619CFF"
f(9)
## [1] "#F8766D" "#D39200" "#93AA00" "#00BA38" "#00C19F" "#00B9E3" "#619CFF" "#DB72FB"
## [9] "#FF61C3"
g <- brewer_pal(type="seq", palette=1)
g(3)
## [1] "#DEEBF7" "#9ECAE1" "#3182BD"
g(9)
## [1] "#F7FBFF" "#DEEBF7" "#C6DBEF" "#9ECAE1" "#6BAED6" "#4292C6" "#2171B5" "#08519C"
## [9] "#08306B"
You can see what brewer_pal
will do with Set3
or any other named palette by using that as the palette
parameter.

hrbrmstr
- 77,368
- 11
- 139
- 205