scale_color_repel: Add a color-repel scale to a ggplot

View source: R/for_ggplot.R

scale_color_repelR Documentation

Add a color-repel scale to a ggplot

Description

scale_color_repel() can be added to a ggplot with +. It calculates a reordered color palette from the plot object, then adds a manual color scale using those optimized colors.

Usage

scale_color_repel(
  nsamp = 50000,
  sim = NULL,
  severity = 0.5,
  verbose = FALSE,
  downsample = 5000,
  polychrome_recolor = FALSE,
  seed = 34,
  col = "colour",
  autoswitch = TRUE,
  layer = 1,
  out_worst = FALSE,
  ...
)

scale_colour_repel(
  nsamp = 50000,
  sim = NULL,
  severity = 0.5,
  verbose = FALSE,
  downsample = 5000,
  polychrome_recolor = FALSE,
  seed = 34,
  col = "colour",
  autoswitch = TRUE,
  layer = 1,
  out_worst = FALSE,
  ...
)

scale_fill_repel(
  nsamp = 50000,
  sim = NULL,
  severity = 0.5,
  verbose = FALSE,
  downsample = 5000,
  polychrome_recolor = FALSE,
  seed = 34,
  col = "fill",
  autoswitch = TRUE,
  layer = 1,
  out_worst = FALSE,
  ...
)

Arguments

nsamp

how many random sampling color combinations to test, default 50000

sim

passing a colorbind simulation function if needed

severity

severity of the color vision defect, between 0 and 1

verbose

whether to print messages

downsample

downsample when too many datapoints are present, or use chull

polychrome_recolor

whether to replace the original colors with polychrome creation

seed

sampling randomization seed

col

colour or fill in ggplot

autoswitch

try to switch between colour and fill automatically

layer

layer to detect color, defaults to first

out_worst

output the worst combination instead of best

...

passed to ggplot2::scale_color_manual() or ggplot2::scale_fill_manual()

Value

object added to a ggplot with +

Examples

a <- ggplot2::ggplot(ggplot2::mpg, ggplot2::aes(displ, hwy)) +
  ggplot2::geom_point(ggplot2::aes(color = as.factor(cyl)))
b <- a + scale_color_repel()
c <- ggplot2::ggplot(ggplot2::mpg, ggplot2::aes(class, fill = as.factor(cyl))) +
  ggplot2::geom_bar() +
  scale_fill_repel()

colorrepel documentation built on July 14, 2026, 9:07 a.m.