palx
is based on the Palx javascript library, basically a port of its core functions using the colorspace
package. Provided a base color, it pulls a set of hues from across the spectrum with the same lightness and saturation, plus a gray color. It then creates shades of those hues from nearly black to nearly white. You probably don't actually want every hue; it's just a good way to get a bunch of colors to choose from.
You can view a palette graphically by running plot(my_palx)
, by setting plot = TRUE
, or by more directly calling plot_palx
. This creates a grid of hue vs. shade tiles.
Usage
palx(
color,
n_hues = 8,
n_shades = 9,
row = NULL,
as_df = FALSE,
plot = FALSE,
labels = FALSE
)
# S3 method for palx
as_tibble(x, ...)
plot_palx(x, ..., labels = FALSE)
Arguments
- color
A string of a color name (
"red"
) or hex code ("#6f54d6"
).' This should be a single value, as it's the color the palette will be based around, though it's not guaranteed that this exact color will be in the final palette.- n_hues
A number between 1 and 12. The number of hues returned will be this + 1, because a gray color will be added.
- n_shades
A number, for the number of shades to return for each hue. Defaults 9; too many more than that will probably become hard to distinguish.
- row
Numeric. If
NULL
, the default, all rows (shades) are returned. Otherwise, only the rows with these indices are returned. Just a shortcut for subsetting the list.- as_df
Logical, whether to return a data frame (
as_df = TRUE
) or a list of character vectors. DefaultsFALSE
.- plot
Logical, whether to call
plot_palx
before returning. This doesn't change what the function returns, it just prints out a ggplot chart and returns the colors as normal. DefaultsFALSE
.- labels
Logical, whether to add labels on each tile giving colors' hex codes. Defaults
FALSE
.- x
The output of calling
palx
, as either a list or data frame- ...
Not used
Value
If as_df = TRUE
, a tibble with n_shades
rows by one column per hue, plus a column giving the shade number. Otherwise, a named list (length n_shades
) of character vectors, where each list item represents one shade. Both the tibble and named list are extended with the "palx" class, so that users can conveniently run plot(my_palx)
or as_tibble(my_palx)
.
Details
Some notes about color:
Hue refers to what would commonly be the general name of a color, e.g. blue or yellow.
Shade refers to how light or dark a color is, e.g. light blue, dark blue.
Saturation refers to the strength of a color, or its distance from a neutral gray.
The color spectrum is broken up into even chunks, but there's a set of wavelengths that appear pretty similar--this shows up in the lime-green-teal-cyan-blue colors. That's just how human eyeballs work I guess.
These palettes shouldn't be used for sequential palettes, even pulling multiple shades from one hue. Good sequential palettes are corrected for perceptual differences in shade, whereas this just takes even steps. Also please don't use rainbow scales for sequential data.
You likely only want one or two shades worth of colors (use the row
arguments), either adjacent for colors that appear "even", or one light and one dark for a paired palette. Saturated colors that aren't too dark or too light work best.
Examples
palx("#9CCC0C") # returns a list
#> $shade01
#> fuschia red orange yellow green teal blue indigo
#> "#290221" "#290202" "#291602" "#1E2902" "#022905" "#022923" "#021029" "#130229"
#> gray
#> "#171813"
#>
#> $shade02
#> fuschia red orange yellow green teal blue indigo
#> "#540543" "#540505" "#542D05" "#3D5405" "#05540B" "#055449" "#052154" "#270554"
#> gray
#> "#2F3227"
#>
#> $shade03
#> fuschia red orange yellow green teal blue indigo
#> "#800866" "#800808" "#804408" "#5D8008" "#088010" "#08806F" "#083380" "#3B0880"
#> gray
#> "#484C3B"
#>
#> $shade04
#> fuschia red orange yellow green teal blue indigo
#> "#AB0A89" "#AB0A0A" "#AB5A0A" "#7DAB0A" "#0AAB16" "#0AAB94" "#0A44AB" "#4F0AAB"
#> gray
#> "#606650"
#>
#> $shade05
#> fuschia red orange yellow green teal blue indigo
#> "#DA0DAE" "#DA0D0D" "#DA730D" "#9FDA0D" "#0DDA1C" "#0DDABD" "#0D57DA" "#640DDA"
#> gray
#> "#7B8265"
#>
#> $shade06
#> fuschia red orange yellow green teal blue indigo
#> "#F332CA" "#F33232" "#F39332" "#BCF332" "#32F340" "#32F3D8" "#3277F3" "#8532F3"
#> gray
#> "#99A086"
#>
#> $shade07
#> fuschia red orange yellow green teal blue indigo
#> "#F66DD9" "#F66D6D" "#F6B26D" "#CFF66D" "#6DF677" "#6DF6E3" "#6D9FF6" "#A86DF6"
#> gray
#> "#B7BCA9"
#>
#> $shade08
#> fuschia red orange yellow green teal blue indigo
#> "#FAA8E8" "#FAA8A8" "#FAD1A8" "#E3FAA8" "#A8FAAE" "#A8FAEE" "#A8C6FA" "#CBA8FA"
#> gray
#> "#D4D7CC"
#>
#> $shade09
#> fuschia red orange yellow green teal blue indigo
#> "#FDE3F8" "#FDE3E3" "#FDF0E3" "#F6FDE3" "#E3FDE5" "#E3FDFA" "#E3EDFD" "#EEE3FD"
#> gray
#> "#F1F2EF"
#>
#> attr(,"class")
#> [1] "palx" "list"
palx("#9CCC0C", as_df = TRUE) # returns a data frame
#> # A tibble: 9 × 10
#> shade fuschia red orange yellow green teal blue indigo gray
#> <dbl> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 1 #290221 #290202 #291602 #1E2902 #022905 #022923 #021029 #130229 #171813
#> 2 2 #540543 #540505 #542D05 #3D5405 #05540B #055449 #052154 #270554 #2F3227
#> 3 3 #800866 #800808 #804408 #5D8008 #088010 #08806F #083380 #3B0880 #484C3B
#> 4 4 #AB0A89 #AB0A0A #AB5A0A #7DAB0A #0AAB16 #0AAB94 #0A44AB #4F0AAB #606650
#> 5 5 #DA0DAE #DA0D0D #DA730D #9FDA0D #0DDA1C #0DDABD #0D57DA #640DDA #7B8265
#> 6 6 #F332CA #F33232 #F39332 #BCF332 #32F340 #32F3D8 #3277F3 #8532F3 #99A086
#> 7 7 #F66DD9 #F66D6D #F6B26D #CFF66D #6DF677 #6DF6E3 #6D9FF6 #A86DF6 #B7BCA9
#> 8 8 #FAA8E8 #FAA8A8 #FAD1A8 #E3FAA8 #A8FAAE #A8FAEE #A8C6FA #CBA8FA #D4D7CC
#> 9 9 #FDE3F8 #FDE3E3 #FDF0E3 #F6FDE3 #E3FDE5 #E3FDFA #E3EDFD #EEE3FD #F1F2EF
# bad examples all with one hue that return weird / not very useful palettes
palx("#ccf4fa") # saturated but too light
#> $shade01
#> fuschia red orange yellow green teal blue indigo
#> "#530842" "#530808" "#532D08" "#3E5308" "#08530D" "#085347" "#082253" "#290853"
#> gray
#> "#293232"
#>
#> $shade02
#> fuschia red orange yellow green teal blue indigo
#> "#AB1189" "#AB1111" "#AB5E11" "#7FAB11" "#11AB1B" "#11AB93" "#1146AB" "#5411AB"
#> gray
#> "#546868"
#>
#> $shade03
#> fuschia red orange yellow green teal blue indigo
#> "#EB31C2" "#EB3131" "#EB8E31" "#B6EB31" "#31EB3D" "#31EBCF" "#3172EB" "#8231EB"
#> gray
#> "#829A9A"
#>
#> $shade04
#> fuschia red orange yellow green teal blue indigo
#> "#F389DC" "#F38989" "#F3BE89" "#D5F389" "#89F390" "#89F3E3" "#89AEF3" "#B789F3"
#> gray
#> "#B7C5C5"
#>
#> $shade05
#> fuschia red orange yellow green teal blue indigo
#> "#FACFF1" "#FACFCF" "#FAE4CF" "#EEFACF" "#CFFAD1" "#CFFAF4" "#CFDEFA" "#E2CFFA"
#> gray
#> "#E2E7E7"
#>
#> $shade06
#> fuschia red orange yellow green teal blue indigo
#> "#FBD9F4" "#FBD9D9" "#FBEAD9" "#F2FBD9" "#D9FBDC" "#D9FBF6" "#D9E5FB" "#E8D9FB"
#> gray
#> "#E8EDED"
#>
#> $shade07
#> fuschia red orange yellow green teal blue indigo
#> "#FCE4F7" "#FCE4E4" "#FCF0E4" "#F6FCE4" "#E4FCE6" "#E4FCF9" "#E4EDFC" "#EFE4FC"
#> gray
#> "#EFF2F2"
#>
#> $shade08
#> fuschia red orange yellow green teal blue indigo
#> "#FDEFFA" "#FDEFEF" "#FDF6EF" "#F9FDEF" "#EFFDF0" "#EFFDFB" "#EFF4FD" "#F5EFFD"
#> gray
#> "#F5F7F7"
#>
#> $shade09
#> fuschia red orange yellow green teal blue indigo
#> "#FEFAFD" "#FEFAFA" "#FEFCFA" "#FDFEFA" "#FAFEFA" "#FAFEFE" "#FAFCFE" "#FCFAFE"
#> gray
#> "#FCFDFD"
#>
#> attr(,"class")
#> [1] "palx" "list"
palx("#6c888d") # not too light, but not saturated enough
#> $shade01
#> fuschia red orange yellow green teal blue indigo
#> "#1C161B" "#1C1616" "#1C1916" "#1A1C16" "#161C16" "#161C1B" "#16181C" "#18161C"
#> gray
#> "#161B1C"
#>
#> $shade02
#> fuschia red orange yellow green teal blue indigo
#> "#3A2D37" "#3A2D2D" "#3A342D" "#363A2D" "#2D3A2D" "#2D3A38" "#2D323A" "#322D3A"
#> gray
#> "#2D383A"
#>
#> $shade03
#> fuschia red orange yellow green teal blue indigo
#> "#584454" "#584444" "#584E44" "#535844" "#445845" "#445855" "#444B58" "#4C4458"
#> gray
#> "#445458"
#>
#> $shade04
#> fuschia red orange yellow green teal blue indigo
#> "#765A70" "#765A5A" "#76695A" "#6F765A" "#5A765C" "#5A7672" "#5A6576" "#665A76"
#> gray
#> "#5B7175"
#>
#> $shade05
#> fuschia red orange yellow green teal blue indigo
#> "#93738C" "#937373" "#938473" "#8A9373" "#739375" "#73938E" "#737F93" "#817393"
#> gray
#> "#748D92"
#>
#> $shade06
#> fuschia red orange yellow green teal blue indigo
#> "#AC92A6" "#AC9292" "#AC9F92" "#A5AC92" "#92AC94" "#92ACA8" "#929BAC" "#9D92AC"
#> gray
#> "#93A7AB"
#>
#> $shade07
#> fuschia red orange yellow green teal blue indigo
#> "#C4B1C0" "#C4B1B1" "#C4BBB1" "#BFC4B1" "#B1C4B3" "#B1C4C1" "#B1B8C4" "#B9B1C4"
#> gray
#> "#B2C0C3"
#>
#> $shade08
#> fuschia red orange yellow green teal blue indigo
#> "#DCD1D9" "#DCD1D1" "#DCD6D1" "#D9DCD1" "#D1DCD1" "#D1DCDA" "#D1D5DC" "#D5D1DC"
#> gray
#> "#D1DADB"
#>
#> $shade09
#> fuschia red orange yellow green teal blue indigo
#> "#F4F0F3" "#F4F0F0" "#F4F2F0" "#F3F4F0" "#F0F4F0" "#F0F4F3" "#F0F1F4" "#F2F0F4"
#> gray
#> "#F0F3F4"
#>
#> attr(,"class")
#> [1] "palx" "list"
palx("#0e91a7") # much better--high saturation, middle lightness
#> $shade01
#> fuschia red orange yellow green teal blue indigo
#> "#21031B" "#210303" "#211203" "#192103" "#032105" "#03211D" "#030E21" "#100321"
#> gray
#> "#101414"
#>
#> $shade02
#> fuschia red orange yellow green teal blue indigo
#> "#450637" "#450606" "#452606" "#334506" "#06450A" "#06453C" "#061C45" "#210645"
#> gray
#> "#21292A"
#>
#> $shade03
#> fuschia red orange yellow green teal blue indigo
#> "#680954" "#680909" "#683909" "#4D6809" "#096810" "#09685B" "#092B68" "#320968"
#> gray
#> "#313E40"
#>
#> $shade04
#> fuschia red orange yellow green teal blue indigo
#> "#8C0C70" "#8C0C0C" "#8C4C0C" "#678C0C" "#0C8C15" "#0C8C79" "#0C3A8C" "#430C8C"
#> gray
#> "#425355"
#>
#> $shade05
#> fuschia red orange yellow green teal blue indigo
#> "#B60F92" "#B60F0F" "#B6630F" "#86B60F" "#0FB61B" "#0FB69E" "#0F4BB6" "#570FB6"
#> gray
#> "#566C6F"
#>
#> $shade06
#> fuschia red orange yellow green teal blue indigo
#> "#EC1FC0" "#EC1F1F" "#EC861F" "#B1EC1F" "#1FEC2E" "#1FECCF" "#1F69EC" "#781FEC"
#> gray
#> "#769195"
#>
#> $shade07
#> fuschia red orange yellow green teal blue indigo
#> "#F260D2" "#F26060" "#F2A960" "#C8F260" "#60F26A" "#60F2DD" "#6094F2" "#9F60F2"
#> gray
#> "#9EB1B4"
#>
#> $shade08
#> fuschia red orange yellow green teal blue indigo
#> "#F7A0E4" "#F7A0A0" "#F7CCA0" "#DEF7A0" "#A0F7A6" "#A0F7EB" "#A0BFF7" "#C6A0F7"
#> gray
#> "#C5D0D2"
#>
#> $shade09
#> fuschia red orange yellow green teal blue indigo
#> "#FCE1F6" "#FCE1E1" "#FCEFE1" "#F4FCE1" "#E1FCE3" "#E1FCF8" "#E1EBFC" "#EDE1FC"
#> gray
#> "#ECF0F1"
#>
#> attr(,"class")
#> [1] "palx" "list"