How to identify with code via ggplot_build whether a plot includes polygons?

Hi ggplot2 experts,

Is it possible to identify with code via ggplot_build whether or not a plot contains a geom that includes polygons?

library(tidyverse)
library(palmerpenguins)
p1 <- penguins |>
  ggplot() +
  geom_point(aes(x = sex, y = body_mass_g))

p1_build <- ggplot_build(p1) 

p2 <- penguins |>
  ggplot() +
  geom_boxplot(aes(x = sex, y = body_mass_g))

p2_build <- ggplot_build(p2)
#> Warning: Removed 2 rows containing non-finite outside the scale range
#> (`stat_boxplot()`).

Created on 2023-12-05 with reprex v2.0.2

Think I wasn't super clear.

I'm trying to detect via code whether a layer contains a geom that is not possible to fill e.g. geom_point, geom_line, geom_linerange etc?

Any help or ideas much appreciated

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.