Package 'DOYPAColors'

Title: Don't Overthink Your Palette of Colors
Description: Access diverse 'ggplot2'-compatible color palettes for simplified data visualization.
Authors: Jorge Mestre [aut, cre]
Maintainer: Jorge Mestre <[email protected]>
License: MIT + file LICENSE
Version: 0.0.2
Built: 2025-02-16 05:47:36 UTC
Source: https://github.com/jmestret/doypacolors

Help Index


DOYPAColors Palette Selector

Description

This function provides access to the DOYPAColors palettes, which are categorized into sequential, diverging, and qualitative types. You can select a palette, define the number of colors, reverse the order, and interpolate colors as a gradient.

Usage

doypa(
  palette = NULL,
  n = NULL,
  reverse = FALSE,
  gradient = FALSE,
  type = "all",
  colorblind = FALSE
)

Arguments

palette

A character string specifying the name of the palette to use. If 'NULL', a random palette will be selected.

n

An integer specifying the number of colors to return. If 'NULL', the full palette is returned.

reverse

A logical value indicating whether to reverse the order of colors in the palette. Default is 'FALSE'.

gradient

A logical value indicating whether to interpolate colors as a gradient of 'n' colors between the first and last colors of the palette. If 'FALSE', returns the first 'n' colors of the palette.

type

A character string specifying the type of palettes to select from: "all", "seq" (sequential), "div" (diverging), or "qual" (qualitative). Default is "all".

colorblind

A logical value indicating whether to restrict the palette to colorblind-friendly options. Default is 'FALSE'.

Value

A character vector of colors.

See Also

'list_doypa_pals' to list available palettes. 'preview_doypa_pals' to preview all color palettes.

Examples

# Get a palette by name
colors <- doypa("buzz")
print(colors)

# Get a random palette
colors <- doypa()
print(colors)

# Get a palette with a specific number of colors
colors <- doypa("google", n = 3)
print(colors)

# Reverse the order of the palette
colors <- doypa("buzz", reverse = TRUE)
print(colors)

# Interpolate colors as a gradient
colors <- doypa("buzz", n = 10, gradient = TRUE)
print(colors)

List Available DOYPAColors Color Palettes

Description

This function provides a list of all available DOYPAColors color palettes, categorized by type: sequential, diverging, and qualitative. It helps users to explore the various color palettes available for use in their visualizations.

Usage

list_doypa_pals()

Value

A named list containing the names of available color palettes for each type: "sequential", "diverging", and "qualitative".

Examples

# List available DOYPAColors color palettes by type
palette_names <- list_doypa_pals()
print(palette_names)

Preview DOYPAColors Palettes

Description

This function generates a visual preview of DOYPAColors color palettes. It helps users explore and select color schemes for their data visualizations by displaying each palette in a grid format.

Usage

preview_doypa_pals(type = "all", colorblind = FALSE)

Arguments

type

Character string specifying the type of palettes to preview. Options are: "all" (default), "seq" (sequential), "div" (diverging), or "qual" (qualitative).

colorblind

Logical. If 'TRUE', restricts the preview to palettes designed with colorblind individuals in mind.

Value

A 'ggplot' visualization displaying the DOYPAColors color palettes, facilitating exploration and selection of color schemes for data visualizations.

Examples

# Preview all available DOYPAColors palettes
preview_doypa_pals()

# Preview only sequential DOYPAColors palettes
preview_doypa_pals(type = "seq")

# Preview colorblind-friendly DOYPAColors palettes
preview_doypa_pals(colorblind = TRUE)

Preview a Single Color Palette

Description

This function generates a visual preview of a DOYPAColors palette with multiple plots. It includes a direct palette preview, a scatter plot, a bar plot, and a heatmap, each using the specified palette.

Usage

preview_pal(palette, seed = NULL)

Arguments

palette

A character string specifying the name of the palette to use.

seed

An optional seed for reproducibility of random numbers.

Value

A 'ggplot' object with multiple plots arranged in a grid, showcasing the color palette in different visualizations.

Examples

# Preview a DOYPAColors palette with multiple plots
preview_pal(palette = "buzz")

Color scale for ggplot2 with DOYPAColors color palettes

Description

This function sets the color scale for ggplot2 using DOYPAColors color palettes, allowing you to apply these palettes to both discrete and continuous data.

Usage

scale_color_doypa(
  palette = NULL,
  n = NULL,
  reverse = FALSE,
  gradient = FALSE,
  discrete = FALSE,
  type = "all",
  colorblind = FALSE,
  ...
)

Arguments

palette

A character string specifying the name of the palette to use. If 'NULL', a random palette will be selected.

n

Number of colors needed. If 'NULL', it will default to the number of levels for discrete scales or to a continuous gradient for continuous scales.

reverse

A logical value indicating whether to reverse the order of colors in the palette. Default is 'FALSE'.

gradient

A logical value indicating whether to interpolate colors as a gradient of 'n' colors between the first and last colors of the palette. If 'FALSE', returns the first 'n' colors of the palette.

discrete

Boolean indicating whether to generate a discrete or continuous palette (default: continuous).

type

A character string specifying the type of palettes to select from: "all", "seq" (sequential), "div" (diverging), or "qual" (qualitative). Default is "all".

colorblind

A logical value indicating whether to restrict the palette to colorblind-friendly options. Default is 'FALSE'.

...

Additional parameters passed to ggplot2's 'scale_color_*' functions.

Value

A 'ggplot2' color scale suitable for adding to a 'ggplot2' object to control color aesthetics.

Examples

library(ggplot2)

# Discrete data
data(iris)
disc <- ggplot(iris, aes(x = Petal.Width, y = Petal.Length, color = Species)) +
  geom_point() + theme_classic()
disc <- disc + scale_color_doypa(palette = "buzz", discrete = TRUE)
print(disc)

# Continuous data
cont <- ggplot(iris, aes(x = Petal.Width, y = Petal.Length, color = Sepal.Length)) +
  geom_point() + theme_classic()
cont <- cont + scale_color_doypa(palette = "buzz")
print(cont)

# Colorblind-friendly palette
disc_colorblind <- ggplot(iris, aes(x = Petal.Width, y = Petal.Length, color = Species)) +
  geom_point() + theme_classic()
disc_colorblind <- disc_colorblind + scale_color_doypa(colorblind = TRUE, discrete = TRUE)
print(disc_colorblind)

Color scale for ggplot2 with DOYPAColors color palettes

Description

This function sets the color scale for ggplot2 using DOYPAColors color palettes, allowing you to apply these palettes to both discrete and continuous data.

Usage

scale_colour_doypa(
  palette = NULL,
  n = NULL,
  reverse = FALSE,
  gradient = FALSE,
  discrete = FALSE,
  type = "all",
  colorblind = FALSE,
  ...
)

Arguments

palette

A character string specifying the name of the palette to use. If 'NULL', a random palette will be selected.

n

Number of colors needed. If 'NULL', it will default to the number of levels for discrete scales or to a continuous gradient for continuous scales.

reverse

A logical value indicating whether to reverse the order of colors in the palette. Default is 'FALSE'.

gradient

A logical value indicating whether to interpolate colors as a gradient of 'n' colors between the first and last colors of the palette. If 'FALSE', returns the first 'n' colors of the palette.

discrete

Boolean indicating whether to generate a discrete or continuous palette (default: continuous).

type

A character string specifying the type of palettes to select from: "all", "seq" (sequential), "div" (diverging), or "qual" (qualitative). Default is "all".

colorblind

A logical value indicating whether to restrict the palette to colorblind-friendly options. Default is 'FALSE'.

...

Additional parameters passed to ggplot2's 'scale_colour_*' functions.

Value

A 'ggplot2' color scale suitable for adding to a 'ggplot2' object to control color aesthetics.


Fill scale for ggplot2 with DOYPAColors color palettes

Description

This function sets the fill scale for ggplot2 using DOYPAColors color palettes, allowing you to use these palettes in your ggplot2 visualizations for both discrete and continuous data.

Usage

scale_fill_doypa(
  palette = NULL,
  n = NULL,
  reverse = FALSE,
  gradient = FALSE,
  discrete = FALSE,
  type = "all",
  colorblind = FALSE,
  ...
)

Arguments

palette

A character string specifying the name of the palette to use. If 'NULL', a random palette will be selected.

n

Number of colors needed. If 'NULL', it will default to the number of levels for discrete scales or to a continuous gradient for continuous scales.

reverse

A logical value indicating whether to reverse the order of colors in the palette. Default is 'FALSE'.

gradient

A logical value indicating whether to interpolate colors as a gradient of 'n' colors between the first and last colors of the palette. If 'FALSE', returns the first 'n' colors of the palette.

discrete

Boolean indicating whether to generate a discrete or continuous palette (default: continuous).

type

A character string specifying the type of palettes to select from: "all", "seq" (sequential), "div" (diverging), or "qual" (qualitative). Default is "all".

colorblind

A logical value indicating whether to restrict the palette to colorblind-friendly options. Default is 'FALSE'.

...

Additional parameters passed to ggplot2's 'scale_fill_*' functions.

Value

A 'ggplot2' fill scale suitable for adding to a 'ggplot2' object to control fill aesthetics.

Examples

library(ggplot2)

# Discrete data
data(iris)
disc <- ggplot(iris, aes(x = Species, y = Petal.Length, fill = Species)) +
  geom_boxplot() + theme_classic()
disc <- disc + scale_fill_doypa(palette = "buzz", discrete = TRUE)
print(disc)

# Continuous data
cont <- ggplot(faithfuld, aes(waiting, eruptions, fill = density)) + 
  geom_tile() + theme_classic()
cont <- cont + scale_fill_doypa(palette = "buzz")
print(cont)

# Colorblind-friendly palette
disc_colorblind <- ggplot(iris, aes(x = Species, y = Petal.Length, fill = Species)) +
  geom_boxplot() + theme_classic()
disc_colorblind <- disc_colorblind + scale_fill_doypa(colorblind = TRUE, discrete = TRUE)
print(disc_colorblind)