Title: | Assess Color Contrast Ratios for Accessibility |
---|---|
Description: | Tools to help choose accessible color combinations based on W3C specifications. |
Authors: | Matt Dray [aut, cre] |
Maintainer: | Matt Dray <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.0.9004 |
Built: | 2024-11-17 06:26:15 UTC |
Source: | https://github.com/matt-dray/coloratio |
Selects whether black or white has the greater contrast with a user-
supplied color. Useful for choosing a text color to overlay on a block-color
background, like value labels over the bars of a bar chart. Calculated as per
cr_get_ratio
. Defaults to black in the case of a tie.
cr_choose_bw(col_bg)
cr_choose_bw(col_bg)
col_bg |
A character vector of colors against which to select either
black or white, whichever has maximum contrast. Supply colors as
six-digit hex values preceded by '#', or named colors from
|
A character vector of values "black" or "white". The length matches the input.
cr_choose_bw(c("white", "gray90", "gray50", "gray10", "black"))
cr_choose_bw(c("white", "gray90", "gray50", "gray10", "black"))
Given a user-supplied color, what's a good color to pair it with for maximum
contrast? Compares provided color against all named R colors, as per
colors
. Contrast calculated as per
cr_get_ratio
.
cr_choose_color(col, n = 1, ex_bw = FALSE)
cr_choose_color(col, n = 1, ex_bw = FALSE)
col |
A character value representing a color. Can be a six-digit hex value preceded by '#', or a named color from |
n |
Number of named colors to return. Color with highest contrast is returned first. |
ex_bw |
Exclude black and variants of white and gray variants? |
A character value that's a named R color.
cr_choose_color("lightyellow")
cr_choose_color("lightyellow")
Calculate the color contrast ratio of two provided colors. Intended as an visual accessibility aid when selecting a text color to place over a single- color background. The output value should be 4.5 or higher to ensure sufficient contrast and readability. This function is currently based on WCAG 2.1. See WCAG for more information about the calculation.
cr_get_ratio(col_1, col_2, quiet = FALSE, view = FALSE)
cr_get_ratio(col_1, col_2, quiet = FALSE, view = FALSE)
col_1 |
Six-digit hex value preceded by '#', or a named color from
|
col_2 |
Six-digit hex value preceded by '#', or a named color from
|
quiet |
Whether to print warning when the ratio value is lower than 4.5. |
view |
Whether to plot a demonstration of col_1 text on a col_2
background, and vice versa, for visual inspection. Uses
|
A double.
cr_get_ratio("#FFFFFF", "white")
cr_get_ratio("#FFFFFF", "white")
Plots text of one color on a background of another color, and vice versa. Used to visualise contrasts.
cr_view_contrast(col_1, col_2)
cr_view_contrast(col_1, col_2)
col_1 |
Six-digit hex value preceded by '#', or a named color from
|
col_2 |
Six-digit hex value preceded by '#', or a named color from
|
Character value or vector.
cr_view_contrast("yellow", "black")
cr_view_contrast("yellow", "black")