In ggplot2, is it possible to identify which aesthetics are set based on the ggplot build object?
library(tidyverse)
p <- ggplot2::faithfuld |>
ggplot() +
geom_contour(aes(x = waiting, y = eruptions, z = density,
col = after_stat(level)),
bins = 8
)
ggplot_build(p)$data[[1]] |> tibble()
#> # A tibble: 829 × 13
#> colour order level x y piece group nlevel PANEL weight linewidth
#> <chr> <dbl> <dbl> <dbl> <dbl> <int> <fct> <dbl> <fct> <dbl> <dbl>
#> 1 #132B43 0.005 0.005 74.7 5.1 1 -1-002-0… 0.143 1 1 0.5
#> 2 #132B43 0.005 0.005 74.5 5.09 1 -1-002-0… 0.143 1 1 0.5
#> 3 #132B43 0.005 0.005 73.9 5.05 1 -1-002-0… 0.143 1 1 0.5
#> 4 #132B43 0.005 0.005 73.8 5.05 1 -1-002-0… 0.143 1 1 0.5
#> 5 #132B43 0.005 0.005 73.3 5.01 1 -1-002-0… 0.143 1 1 0.5
#> 6 #132B43 0.005 0.005 73.1 4.99 1 -1-002-0… 0.143 1 1 0.5
#> 7 #132B43 0.005 0.005 72.7 4.96 1 -1-002-0… 0.143 1 1 0.5
#> 8 #132B43 0.005 0.005 72.4 4.92 1 -1-002-0… 0.143 1 1 0.5
#> 9 #132B43 0.005 0.005 72.3 4.91 1 -1-002-0… 0.143 1 1 0.5
#> 10 #132B43 0.005 0.005 71.9 4.86 1 -1-002-0… 0.143 1 1 0.5
#> # ℹ 819 more rows
#> # ℹ 2 more variables: linetype <dbl>, alpha <lgl>
ggplot_build(p)$layout
#> <ggproto object: Class Layout, gg>
#> coord: <ggproto object: Class CoordCartesian, Coord, gg>
#> aspect: function
#> backtransform_range: function
#> clip: on
#> default: TRUE
#> distance: function
#> expand: TRUE
#> is_free: function
#> is_linear: function
#> labels: function
#> limits: list
#> modify_scales: function
#> range: function
#> render_axis_h: function
#> render_axis_v: function
#> render_bg: function
#> render_fg: function
#> setup_data: function
#> setup_layout: function
#> setup_panel_guides: function
#> setup_panel_params: function
#> setup_params: function
#> train_panel_guides: function
#> transform: function
#> super: <ggproto object: Class CoordCartesian, Coord, gg>
#> coord_params: list
#> facet: <ggproto object: Class FacetNull, Facet, gg>
#> compute_layout: function
#> draw_back: function
#> draw_front: function
#> draw_labels: function
#> draw_panels: function
#> finish_data: function
#> init_scales: function
#> map_data: function
#> params: list
#> setup_data: function
#> setup_params: function
#> shrink: TRUE
#> train_scales: function
#> vars: function
#> super: <ggproto object: Class FacetNull, Facet, gg>
#> facet_params: list
#> finish_data: function
#> get_scales: function
#> layout: data.frame
#> map_position: function
#> panel_params: list
#> panel_scales_x: list
#> panel_scales_y: list
#> render: function
#> render_labels: function
#> reset_scales: function
#> resolve_label: function
#> setup: function
#> setup_panel_guides: function
#> setup_panel_params: function
#> train_position: function
#> super: <ggproto object: Class Layout, gg>
Created on 2023-08-25 with reprex v2.0.2