How to extract the fill colours from a ggplot object?

Solution 1:

Try building the plot,

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

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