Skip to contents

Match list of arguments to arguments of geometry

Usage

match_geom_args(
  geom,
  args,
  add_aes = TRUE,
  mapping = list(),
  add_mapping = FALSE,
  exclude_args = NULL,
  envir = "ggplot2"
)

Arguments

geom

Character. name of the geometry.

args

Named list, parameters to be matched to the geometry arguments.

add_aes

Add aesthetics parameters (like size, fill, ...).

mapping

Mapping used in plot, to avoid setting fixed aesthetics parameters.

add_mapping

Add the mapping as an argument.

exclude_args

Character vector of arguments to exclude, default is to exclude aesthetics names.

envir

Package environment to search in.

Value

a list().

Examples

# List of parameters
params <- list(
  bins = 30,
  scale = "width",
  adjust = 2,
  position = "stack",
  size = 1.6,
  fill = "#112246"
)

# Search arguments according to geom
match_geom_args(geom = "histogram", args = params)
#> $bins
#> [1] 30
#> 
#> $position
#> [1] "stack"
#> 
#> $fill
#> [1] "#112246"
#> 
match_geom_args(geom = "violin", args = params)
#> $scale
#> [1] "width"
#> 
#> $position
#> [1] "stack"
#> 
#> $fill
#> [1] "#112246"
#> 
match_geom_args(geom = "bar", args = params, add_aes = FALSE)
#> $position
#> [1] "stack"
#> 
match_geom_args(geom = "point", args = params)
#> $position
#> [1] "stack"
#> 
#> $size
#> [1] 1.6
#> 
#> $fill
#> [1] "#112246"
#> 
match_geom_args(geom = "point", args = params, add_aes = FALSE)
#> $position
#> [1] "stack"
#>