Get a list of colors used in ggplot2 graphics?

Possible duplicate:
How to extract fill colors from ggplot object?

In an arbitrary ggplot plot, let's say

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

there is a way to extract the code of the colors used (that is, a variable with the name "value", which we modify with the command

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

)?

I would like to get the colors used to change only one.

Thanks,

Francois

+4
source share
1 answer

For a discrete scale (with the default scale_colour_hue ), the hue_pal function in the scales package is used. For example, with three levels of factors:

 R> library(scales) R> scales::hue_pal()(3) [1] "#F8766D" "#00BA38" "#619CFF" 
+12
source

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


All Articles