Compare the relative luminance of two colours using the Web Content Accessibility Guidelines. The ratio ranges from 1 for identical colours to 21 for black against white. The guidelines specify at least 4.5 for body text and 3 for large text and graphical objects.
Arguments
- colour, background
Colours, in any form
col2rgbaccepts. Vectors are recycled against each other.
Details
Embedded transparency is composited against the background. A transparent background is first composited over white.
See also
check_contrast(), which applies this to a whole plot.
Examples
contrast_ratio("black", "white")
#> [1] 21
contrast_ratio(c("grey20", "grey50", "grey80"), "white")
#> [1] 12.634654 4.004107 1.605929