The {taylor} package comes with it’s own class of color palettes, inspired by the work of Josiah Parry in the {cpcinema} package.

Creating palettes

{taylor} uses {vctrs} to create a special vector class of color palettes that can be used to create and visualize palettes. We can create a palette using the color_palette() function. We only have to pass a vector of hexadecimal values or valid R color (from colors()), and a palette is created that will print a preview of the colors.

library(taylor)

my_pal <- color_palette(c("firebrick", "turquoise", "#0051ba"))
my_pal
#> <color_palette[3]>
#>     #B22222 
#>     #40E0D0 
#>     #0051ba

We can also use color_palette() on an existing palette to interpolate additional values, by specifying that we want to make a continuous palette out of the few discrete colors that were originally specified.

my_big_pal <- color_palette(my_pal, n = 10, type = "continuous")
my_big_pal
#> <color_palette[10]>
#>     #B22222 
#>     #984C48 
#>     #7F766F 
#>     #66A096 
#>     #4CCABC 
#>     #38D0CD 
#>     #2AB0C8 
#>     #1C90C3 
#>     #0E70BE 
#>     #0051BA

Similarly, if we have a large color palette, we can select just a few representative colors.

my_small_pal <- color_palette(my_big_pal, n = 5)
my_small_pal
#> <color_palette[5]>
#>     #B22222 
#>     #7F766F 
#>     #4CCABC 
#>     #2AB0C8 
#>     #0E70BE

Built-in palettes

The {taylor} package comes with a few palettes built-in, based on Taylor Swift’s album covers. There can be viewed using taylor::album_palettes.

album_palettes
#> $taylor_swift
#> <color_palette[5]>
#>     #1D4737 
#>     #1BAEC6 
#>     #523d28 
#>     #AD8562 
#>     #E7DBCC 
#> 
#> $fearless
#> <color_palette[5]>
#>     #6B5E57 
#>     #776456 
#>     #976F34 
#>     #CBA863 
#>     #E1D4C2 
#> 
#> $fearless_tv
#> <color_palette[5]>
#>     #624324 
#>     #A47F45 
#>     #CAA462 
#>     #C5AA7C 
#>     #EEDBA9 
#> 
#> $speak_now
#> <color_palette[5]>
#>     #2E1924 
#>     #6C3127 
#>     #833C63 
#>     #D1A0C7 
#>     #F5E8E2 
#> 
#> $red
#> <color_palette[5]>
#>     #201F39 
#>     #A91E47 
#>     #7E6358 
#>     #B0A49A 
#>     #DDD8C9 
#> 
#> $`1989`
#> <color_palette[5]>
#>     #5D4E5D 
#>     #846578 
#>     #92573C 
#>     #C6B69C 
#>     #D8D8CF 
#> 
#> $reputation
#> <color_palette[5]>
#>     #2C2C2C 
#>     #515151 
#>     #5B5B5B 
#>     #6E6E6E 
#>     #B9B9B9 
#> 
#> $lover
#> <color_palette[5]>
#>     #8C4F66 
#>     #9C8083 
#>     #847262 
#>     #6098B6 
#>     #EBBED3 
#> 
#> $folklore
#> <color_palette[5]>
#>     #3E3E3E 
#>     #545454 
#>     #5C5C5C 
#>     #949494 
#>     #EBEBEB 
#> 
#> $evermore
#> <color_palette[5]>
#>     #160E10 
#>     #421E18 
#>     #D37F55 
#>     #85796D 
#>     #E0D9D7

Or we can access a single palette.

album_palettes$fearless_tv
#> <color_palette[5]>
#>     #624324 
#>     #A47F45 
#>     #CAA462 
#>     #C5AA7C 
#>     #EEDBA9

Also included is a palette that includes one representative color from each album, taylor::album_compare.

album_compare
#> <color_palette[10]>
#>     #1BAEC6 
#>     #976F34 
#>     #624324 
#>     #833C63 
#>     #A91E47 
#>     #846578 
#>     #2C2C2C 
#>     #EBBED3 
#>     #949494 
#>     #421E18

Using color palettes with {ggplot2}

The {taylor} package comes with a set of functions built in for plotting in {ggplot2} with the album palettes. For example, we can use scale_fill_taylor_c() to create a continuous scale based on one of the album palettes. For more details on how to use the scale functions included in {taylor}, check out vignette("plotting").

library(ggplot2)

ggplot(faithfuld, aes(waiting, eruptions, fill = density)) +
  geom_tile() +
  theme_minimal() -> p

p + scale_fill_taylor_c(album = "Fearless (Taylor's Version)")

A heatmap showing a positive relationship between the waiting time between eruptions and the length of eruptions at the Old Faithful geyser. The heat map is colored using the palette based on Fearless (Taylor's Version), which moves from a dark golden brown for low density combinations up to bright gold for high density combinations.

You can also use your custom palettes with {ggplot2}. For example, we can create a palette of greens, and then use ggplot2::scale_fill_gradientn() or ggplot2::scale_color_gradientn() to use the palette.

green_pal <- color_palette(c("#E5F5E0", "#A1D99B", "#31A354"))
green_pal
#> <color_palette[3]>
#>     #E5F5E0 
#>     #A1D99B 
#>     #31A354
ggplot(faithfuld, aes(waiting, eruptions, fill = density)) +
  geom_tile() +
  scale_fill_gradientn(colors = green_pal) +
  theme_minimal()

The same heatmap as the previous figure, but instead of the fill using a palette based on Fearless (Taylor's Version), the color palette goes from light green to dark green.

Finally, if we have a discrete scale, we can use ggplot2::scale_fill_manual() or ggplot2::scale_color_manual(). Here, we use the {palmerpenguins} to map our palette to the species of penguin.

library(palmerpenguins)

penguin_pal <- color_palette(c("firebrick", "goldenrod", "navy"))
penguin_pal
#> <color_palette[3]>
#>     #B22222 
#>     #DAA520 
#>     #000080
ggplot(penguins, aes(x = bill_length_mm, y = bill_depth_mm)) +
  geom_point(aes(shape = species, color = species), size = 3) +
  scale_color_manual(values = penguin_pal) +
  theme_minimal()

A scatter plot with bill length on the x-axis and bill depth on the y-axis. The shape and color of the points correspond to the species of penguin, with colors derived from our custom color palette. Adelie penguins are shown in red circles, Chinstrap penguins in yellow triangles, and Gentoo penguins in blue squares.