edit_colors: Edit colors in existing plot or grid object

View source: R/edit_colors.R

edit_colorsR Documentation

Edit colors in existing plot or grid object

Description

The function edit_colors() can modify colors in existing ggplot2 plots, grid objects, or R base plots provided as recorded plots.

Usage

edit_colors(plot = last_plot(), colfun = passthrough, fillfun = NULL,
  ...)

edit_grob_colors(grob, colfun, fillfun, ...)

Arguments

plot

The plot or grid graphics object to edit. The function edit_colors() can accept any object that can be handled by cowplot::plot_to_gtable().

colfun

The function used to edit colors (col in gpar objects).

fillfun

The function used to edit fill colors (fill in gpar objects). By default the same as colfun.

...

Other parameters to be given to functions colfun and fillfun.

grob

The grid graphics object to edit.

Examples

library(ggplot2)
library(colorspace) # for desaturate
p <- ggplot(iris, aes(Sepal.Width, fill=Species)) +
  geom_density(alpha = 0.7)

p2 <- edit_colors(p, deutan)
p3 <- edit_colors(p, tritan, sev = 7)
p4 <- edit_colors(p, desaturate)
cowplot::plot_grid(p, p2, p3, p4)

clauswilke/colorblindr documentation built on July 29, 2023, 2:17 p.m.