Intro Thoughts

Status Quo

library(tidyverse)
library(tidyverse)


ggplot() + 
theme(panel.background = element_rect(fill = "green"))

theme(panel.background = element_rect(fill = "green"))
## <theme> List of 1
##  $ panel.background: <ggplot2::element_rect>
##   ..@ fill         : chr "green"
##   ..@ colour       : NULL
##   ..@ linewidth    : NULL
##   ..@ linetype     : NULL
##   ..@ linejoin     : NULL
##   ..@ inherit.blank: logi FALSE
##  @ complete: logi FALSE
##  @ validate: logi TRUE
general_rect <- theme(panel.background = element_rect(fill = "pink"))
names(general_rect) <- "plot.background"

ggplot() + 
  general_rect

reset_rect_component <- function(){

    theme_grey_settings <- theme_gray()
    component_settings <- theme_grey_settings[[component]]
    component_settings <- element_rect() 
    
    component_settings$fill <- fill
    component_settings$colour <- colour
    component_settings$linewidth <- linewidth
    component_settings$linetype <- linetype
    component_settings$linejoin <- linejoin

    component_settings
}

args_rect <- formals(element_rect)
args_rect$... <- NULL
args_rect$size <- NULL

formals(reset_rect_component) <- args_rect |>  modifyList(list(component = "panel.background"))

ggplot() + 
  reset_rect_component(fill = "green")
theme_panel_background <- function(){
  
  args <- list(fill = fill, colour = colour, 
               linewidth = linewidth, linetype = linetype, 
               linejoin = linejoin, component = component)
  
  do.call(reset_rect_component, args)
  
}

formals(theme_panel_background) <- args_rect |> modifyList(list(component = "panel.background"))


ggplot() + 
  reset_rect_component("green")

Experiment

ggplot() #+
theme(panel.background = element_rect(fill = "grey4")) |> str()

element_rect_formals <- formals(element_rect)
element_rect_formals$... <- NULL
element_rect_formals$size <- NULL



theme(panel.background = element_rect()) |> str()

theme_panel_background <- function(fill = NULL, colour = NULL, linewidth = NULL, 
                                   linetype = NULL, linejoin = NULL){
  
  
}


respecified[["panel.background"]][["fill"]]

ggplot() + 
  aes() +
  theme_panel_background(fill = "brown")

theme(panel.background = element_rect())$fill




theme_panel_background()
theme_panel_background(fill = "hi")

theme(panel.background = do.call(element_rect, element_rect_formals |> as.list()))

theme_panel_background(fill = "black")

ggplot() + 
  theme_panel_background(fill = "grey4")

Closing remarks, Other Relevant Work, Caveats