Suppose I draw the following plot composed of two polygons :
library(ggplot2)
polys <- data.frame(
id = rep(factor(c("1","2")),each=4),
x = c(1,2,2,1,2,3,3,2),
y = c(1,1,2,2,1,1,2,2),
value = rep(c(3, 4), each=4)
)
(p <- ggplot(polys, aes(x=x, y=y)) + geom_polygon(aes(fill=value, group=id)))
Which gives :

Is there a way to determine the color given to each polygon from the p ggplot object ? I’ve played a bit with str(p) but didn’t find anything useful for this.
Thanks in advance for any hint !
You can do that by:
ggplotGrobmakes grob treegetGrobextracts grobs that you want by usinggPath$gp$fillshows the color of the polygon.In the future version of ggplot2, probably you will get information more easily.