Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

get list of colors used in a ggplot2 plot? [duplicate]

Tags:

r

ggplot2

Possible Duplicate:
How to extract the fill colours from a ggplot object?

In an arbitrary ggplot plot, say

p <- ggplot(data=PlantGrowth, aes(x=group, y=weight, fill=group)) + geom_boxplot()

is there a way to extract the code of the colors that were used (i.e. the variable named "values" that we modify with the command

p + scale_fill_manual(values=c("#999999", "#E69F00", "#56B4E9")) 

) ?

I would like to get the colors used in order to modify only one.

Thank you,

François

like image 978
fstevens Avatar asked Nov 15 '12 11:11

fstevens


1 Answers

For a discrete scale (with default setting scale_colour_hue) the function hue_pal in package scales is used. E.g., with three factor levels:

R> library(scales)
R> scales::hue_pal()(3)
[1] "#F8766D" "#00BA38" "#619CFF"
like image 194
rcs Avatar answered Nov 13 '22 06:11

rcs