Skip to content

Modify geom/stat aesthetic defaults for future plots

Usage

update_geom_defaults(geom, new)

update_stat_defaults(stat, new)

Arguments

new

Named list of aesthetics.

stat, geom

Name of geom/stat to modify (like "point" or "bin"), or a Geom/Stat object (like GeomPoint or StatBin).

Examples


# updating a geom's default aesthetic settings
# example: change geom_point()'s default color
GeomPoint$default_aes
#> Aesthetic mapping: 
#> * `shape`  -> 19
#> * `colour` -> "black"
#> * `size`   -> 1.5
#> * `fill`   -> NA
#> * `alpha`  -> NA
#> * `stroke` -> 0.5
update_geom_defaults("point", aes(color = "red"))
GeomPoint$default_aes
#> Aesthetic mapping: 
#> * `shape`  -> 19
#> * `colour` -> "red"
#> * `size`   -> 1.5
#> * `fill`   -> NA
#> * `alpha`  -> NA
#> * `stroke` -> 0.5
ggplot(mtcars, aes(mpg, wt)) + geom_point()


# reset default
update_geom_defaults("point", aes(color = "black"))


# updating a stat's default aesthetic settings
# example: change stat_bin()'s default y-axis to the density scale
StatBin$default_aes
#> Aesthetic mapping: 
#> * `x`      -> `after_stat(count)`
#> * `y`      -> `after_stat(count)`
#> * `weight` -> 1
update_stat_defaults("bin", aes(y = after_stat(density)))
StatBin$default_aes
#> Aesthetic mapping: 
#> * `x`      -> `after_stat(count)`
#> * `y`      -> `after_stat(density)`
#> * `weight` -> 1
ggplot(data.frame(x = rnorm(1e3)), aes(x)) +
  geom_histogram() +
  geom_function(fun = dnorm, color = "red")
#> `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.


# reset default
update_stat_defaults("bin", aes(y = after_stat(count)))