How to extract the fill colours from a ggplot object?

Try building the plot,

g <- ggplot_build(p)
unique(g$data[[1]]["fill"])

      fill
1  #1B9E77
16 #D95F02
28 #7570B3

Leave a Comment