Cover and Logo Design

The cover of the book is inspired by the fast growing generative art community in R. Generative art refers to art that in whole or in part has been created with the use of an autonomous system. Instead of creating random dynamics we rely on what is core to the book: The evolution of financial markets. Each circle in the cover figure corresponds to daily market return within one year of our sample. Deviations from the circle line indicate positive or negative returns. The colors are determined by the standard deviation of market returns during the particular year. The few lines of code below replicate the entire figure. We use the Wes Andersen color palette (also throughout the entire book), provided by the package wesanderson (Ram and Wickham 2018)

library(tidyverse)
library(RSQLite)
library(wesanderson)

tidy_finance <- dbConnect(
  SQLite(),
  "data/tidy_finance_r.sqlite",
  extended_types = TRUE
)

factors_ff3_daily <- tbl(
  tidy_finance,
  "factors_ff3_daily"
) |>
  collect()

data_plot <- factors_ff3_daily |>
  select(date, mkt_excess) |>
  group_by(year = floor_date(date, "year")) |>
  mutate(group_id = cur_group_id())

data_plot <- data_plot |>
  group_by(group_id) |>
  mutate(
    day = 2 * pi * (1:n()) / 252,
    ymin = pmin(1 + mkt_excess, 1),
    ymax = pmax(1 + mkt_excess, 1),
    vola = sd(mkt_excess)
  ) |>
  filter(year >= "1962-01-01" & year <= "2021-12-31")

levels <- data_plot |>
  distinct(group_id, vola) |>
  arrange(vola) |>
  pull(vola)

cp <- coord_polar(
  direction = -1,
  clip = "on"
)

cp$is_free <- function() TRUE
colors <- wes_palette("Zissou1",
  n_groups(data_plot),
  type = "continuous"
)

cover <- data_plot |>
  mutate(vola = factor(vola, levels = levels)) |>
  ggplot(aes(
    x = day,
    y = mkt_excess,
    group = group_id,
    fill = vola
  )) +
  cp +
  geom_ribbon(aes(
    ymin = ymin,
    ymax = ymax,
    fill = vola
  ), alpha = 0.90) +
  theme_void() +
  facet_wrap(~group_id,
    ncol = 10,
    scales = "free"
  ) +
  theme(
    strip.text.x = element_blank(),
    legend.position = "None",
    panel.spacing = unit(-5, "lines")
  ) +
  scale_fill_manual(values = colors)

ggsave(
 plot = cover,
 width = 10,
 height = 6,
 filename = "images/cover.png",
 bg = "white"
)

To generate our logo, we focus on year 2021 - the end of the sample period at the time we published tidy-finance.org for the first time.

logo <- data_plot |>
  ungroup() |> 
  filter(year == "2021-01-01") |> 
  mutate(vola = factor(vola, levels = levels)) |>
  ggplot(aes(
    x = day,
    y = mkt_excess,
    fill = vola
  )) +
  cp +
  geom_ribbon(aes(
    ymin = ymin,
    ymax = ymax,
    fill = vola
  ), alpha = 0.90) +
  theme_void() +
  theme(
    strip.text.x = element_blank(),
    legend.position = "None",
    plot.margin = unit(c(-0.15,-0.15,-0.15,-0.15), "null")
  ) +
  scale_fill_manual(values =  "white") 

ggsave(
 plot = logo,
 width = 840,
 height = 840,
 units = "px",
 filename = "images/logo-website-white.png",
)

ggsave(
 plot = logo +
    scale_fill_manual(values =  wes_palette("Zissou1")[1]), 
 width = 840,
 height = 840,
 units = "px",
 filename = "images/logo-website.png",
)

Here is the code to generate the vector graphics for our buttons.

button_r <- data_plot |>
  ungroup() |> 
  filter(year == "2000-01-01") |> 
  mutate(vola = factor(vola, levels = levels)) |>
  ggplot(aes(
    x = day,
    y = mkt_excess,
    fill = vola
  )) +
  cp +
  geom_ribbon(aes(
    ymin = ymin,
    ymax = ymax,
    fill = vola
  ), alpha = 0.90) +
  theme_void() +
  theme(
    strip.text.x = element_blank(),
    legend.position = "None",
    plot.margin = unit(c(-0.15,-0.15,-0.15,-0.15), "null")
  ) 

ggsave(
 plot = button_r +
    scale_fill_manual(values =  wes_palette("Zissou1")[1]), 
 width = 100,
 height = 100,
 units = "px",
 filename = "images/button-r-blue.svg",
)

ggsave(
 plot = button_r +
    scale_fill_manual(values =  wes_palette("Zissou1")[4]), 
 width = 100,
 height = 100,
 units = "px",
 filename = "images/button-r-orange.svg",
)

button_python <- data_plot |>
  ungroup() |> 
  filter(year == "1991-01-01") |> 
  mutate(vola = factor(vola, levels = levels)) |>
  ggplot(aes(
    x = day,
    y = mkt_excess,
    fill = vola
  )) +
  cp +
  geom_ribbon(aes(
    ymin = ymin,
    ymax = ymax,
    fill = vola
  ), alpha = 0.90) +
  theme_void() +
  theme(
    strip.text.x = element_blank(),
    legend.position = "None",
    plot.margin = unit(c(-0.15,-0.15,-0.15,-0.15), "null")
  ) 

ggsave(
 plot = button_python +
    scale_fill_manual(values =  wes_palette("Zissou1")[1]), 
 width = 100,
 height = 100,
 units = "px",
 filename = "images/button-python-blue.svg",
)

ggsave(
 plot = button_python +
    scale_fill_manual(values =  wes_palette("Zissou1")[4]), 
 width = 100,
 height = 100,
 units = "px",
 filename = "images/button-python-orange.svg",
)

References

Ram, Karthik, and Hadley Wickham. 2018. wesanderson: A Wes Anderson palette generator. https://CRAN.R-project.org/package=wesanderson.