adjust_sub_colors: Create sub cluster colors

View source: R/color-palettes-and-spectra.R

adjust_sub_colorsR Documentation

Create sub cluster colors

Description

Creates a vector of colors based on sub grouping.

Usage

adjust_sub_colors(
  input,
  clrp,
  clrp.adjust = NULL,
  clr.bottom = "white",
  offset = 1,
  into = c("main", "sub"),
  sep = "_",
  alphabetically = TRUE
)

Arguments

input

Character vector of group names.

clrp

Character value. The color palette of choice. Run confuns::all_color_palettes() to see all valid input choices.

(Ignored if variable is numeric)

clrp.adjust

Named character vector or NULL. If character, it adjusts the colors that are used to represent the groups. Names of the input vector must refer to the group and the respective named element denotes the color with which to represent the group.

clr.bottom

Character value. The color up to which the sub panel for each sub grouping is created.

offset

Integer value. If 1, the default, the last sub group is mapped to the color that comes directly before clr.bottom.

into

Character vector of length two. A combination of 'main', 'sub'. If into = c('main', 'sub') string parts before sep are considered the main grouping and strings parts after sep are considered the sub part. Works the other way around for into = c('sub', 'main').

sep

Character value. Is used to cut the sub grouping information from the variabel in main.

alphabetically

If TRUE, sub groups are sorted alphabetically before being mapped to colors.

Value

Named character vector. Names are the groups. Values are the colors.

Examples


library(tidyverse)
library(confuns)

df <-
 mutate(
  .data = iris,
  numbers = sample(1:3, size = nrow(iris), replace = T),
  spec_sub = str_c(Species, numbers, sep = ".") %>% as.factor()
 )

adjust_out <- adjust_sub_colors(input = df$spec_sub, clrp = "npg", sep = ".")

print(adjust_out)

ggplot(data = df, mapping = aes(x = Sepal.Width, y = Sepal.Length)) +
 geom_point(mapping = aes(color = spec_sub), size = 4) +
 scale_color_add_on(
  clrp = "npg",
  variable = df$spec_sub,
  clrp.adjust = adjust_out
  )


kueckelj/confuns documentation built on July 4, 2024, 4:53 p.m.