Skip to content

What are the default parameters for a plot layer?

Usage

get_default_params(p, geom, params = NULL, i = NULL)

Arguments

p

A ggplot object

geom

A character string found in the suffix of a ggplot2 geom function, e.g. "point".

params

A character vector. get_default_params() returns the default parameter value with a name matching each string in params. If params is NULL (the default), the default values for all parameters are returned.

i

A numerical index, e.g. 1.

Value

A named list of the same length as params, or, if params is NULL, a named list of default values for all parameters of geom.

See also

Other functions for checking geom parameters: uses_geom_params()

Examples

require(ggplot2)

p <- ggplot(data = mpg, mapping = aes(x = displ, y = hwy)) +
  geom_smooth(aes(color = class))

# Returns the parameters the ggplot would use by default for a layer
get_default_params(p, "smooth", "linetype")
#> $linetype
#> [1] 1
#> 
get_default_params(p, "smooth", c("se", "level"))
#> $se
#> [1] TRUE
#> 
#> $level
#> [1] 0.95
#> 
get_default_params(p, "smooth")
#> $colour
#> [1] "#3366FF"
#> 
#> $fill
#> [1] "grey60"
#> 
#> $linewidth
#> [1] 1
#> 
#> $linetype
#> [1] 1
#> 
#> $weight
#> [1] 1
#> 
#> $alpha
#> [1] 0.4
#> 
#> $na.rm
#> [1] FALSE
#> 
#> $orientation
#> [1] NA
#> 
#> $se
#> [1] TRUE
#> 
#> $method
#> NULL
#> 
#> $formula
#> NULL
#> 
#> $n
#> [1] 80
#> 
#> $fullrange
#> [1] FALSE
#> 
#> $level
#> [1] 0.95
#> 
#> $method.args
#> list()
#> 
#> $span
#> [1] 0.75
#> 

# If a parameter does not exist, returns NULL
get_default_params(p, "smooth", "shape")
#> $shape
#> NULL
#> 

# The colo(u)r aesthetic can be matched with or without a u
get_default_params(p, "smooth", "color")
#> $color
#> [1] "#3366FF"
#> 
get_default_params(p, "smooth", "colour")
#> $colour
#> [1] "#3366FF"
#>