Learn R Programming

ggplot2 (version 4.0.1)

update_geom_defaults: Modify geom/stat aesthetic defaults for future plots

Description

Functions to update or reset the default aesthetics of geoms and stats.

Usage

update_geom_defaults(geom, new)

update_stat_defaults(stat, new)

reset_geom_defaults()

reset_stat_defaults()

Arguments

new

One of the following:

  • A named list of aesthetics to serve as new defaults.

  • NULL to reset the defaults.

stat, geom

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

Examples

Run this code

# updating a geom's default aesthetic settings
# example: change geom_point()'s default color
GeomPoint$default_aes
update_geom_defaults("point", aes(color = "red"))
GeomPoint$default_aes
ggplot(mtcars, aes(mpg, wt)) + geom_point()

# reset single default
update_geom_defaults("point", NULL)

# reset all defaults
reset_geom_defaults()

# updating a stat's default aesthetic settings
# example: change stat_bin()'s default y-axis to the density scale
StatBin$default_aes
update_stat_defaults("bin", aes(y = after_stat(density)))
StatBin$default_aes
ggplot(data.frame(x = rnorm(1e3)), aes(x)) +
  geom_histogram() +
  geom_function(fun = dnorm, color = "red")

# reset single default
update_stat_defaults("bin", NULL)

# reset all defaults
reset_stat_defaults()

Run the code above in your browser using DataLab