## ----options, include = FALSE-------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  out.width = "100%"
)

## ----sets, message=FALSE, warning=FALSE, fig.width=10, fig.height=8-----------
library(ggfoundry)
library(dplyr)
library(forcats)
library(stringr)

df <- shapes_cast() |> 
  filter(!str_ends(shape, "3|4|5|6")) |> 
  mutate(x = row_number(), shape = fct_inorder(shape), .by = set)

df |> 
  ggplot(aes(x, set)) +
  geom_text(aes(label = shape), nudge_y = -0.5, colour = "grey40", size = 3) +
  geom_casting(aes(shape = shape), size = 0.11, fill = "skyblue") +
  scale_shape_manual(values = as.character(df$shape)) +
  scale_x_continuous(expand = expansion(add = 0.5)) +
  scale_y_discrete(expand = expansion(add = 0.7)) +
  labs(x = NULL, y = NULL, caption = "sunflowers 1-8 available") +
  theme_minimal() +
  theme(
    text = element_text(colour = "grey70"),
    axis.text.y = element_text(angle = 90, hjust = 0.5),
    axis.text.x = element_blank(),
    axis.ticks.x = element_blank(),
    legend.position = "none"
    )

## -----------------------------------------------------------------------------
# Toy Data
set.seed(123)

random_walk <- \(x, y, z) cumsum(rnorm(x, mean = y, sd = sqrt(z)))

df <- data.frame(
  x = rep(1:10, 2),
  y = c(
    random_walk(10, 1, 1),
    random_walk(10, 3, 1.3)
  ),
  group = factor(c(rep(1, 10), rep(2, 10)))
)

# Plot with geom_casting()
df |>
  ggplot(aes(x, y, shape = group, colour = group, fill = group)) +
  geom_line(show.legend = FALSE) +
  geom_casting() +
  scale_colour_manual(values = c("darkred", "darkgreen")) +
  scale_fill_manual(values = c("pink", "lightgreen")) +
  scale_shape_manual(values = c("cross1", "cross2")) +
  labs(title = "ggfoundry") +
  theme_bw() +
  theme(plot.subtitle = element_text(size = 10))

## ----bowls, message=FALSE, warning=FALSE, fig.width=11, fig.height=4----------
bowls <- data.frame(
  x = 1:7,
  temperature = c(5, 18, 32, 47, 63, 81, 96)
)

bowls |>
  ggplot(
    aes(
      x, 1, fill = temperature,
      shape = cut(temperature, 3, labels = c("Cold", "Just right", "Hot"))
    )
  ) +
  geom_casting(colour = "#272626", size = 0.72) +
  geom_text(aes(y = 0.35, label = temperature), size = 4) +
  scale_shape_manual(
    values = c("bowl0", "bowl1", "bowl2"),
    guide = guide_legend(
      override.aes = list(fill = c("#240691", "#C8437B", "#F8DF25")),
      keyheight = unit(2.5, "lines"), default.unit = "line"
    )
  ) +
  scale_fill_viridis_c(
    limits = c(0, 100), begin = 0.04, end = 0.94, option = "plasma",
    guide = "none"
  ) +
  scale_x_continuous(limits = c(0.35, 7.65), expand = expansion(mult = 0)) +
  scale_y_continuous(limits = c(0, 1.85), expand = expansion(mult = 0)) +
  labs(title = "Hot, just right or cold", shape = "Serving") +
  theme_void() +
  theme(legend.position = "bottom")

## ----coffee-autumn, message=FALSE, warning=FALSE, fig.width=11, fig.height=3----
cafe <- data.frame(
  x = 1:6,
  roast = c(8, 24, 42, 60, 78, 95),
  vessel = c("cup", "mug", "takeaway", "coffeebean", "pumpkin", "jackolantern")
)

cafe |>
  ggplot(aes(x, 1, fill = roast, shape = vessel)) +
  geom_casting(colour = "#33302D", size = 0.34) +
  scale_shape_manual(
    values = setNames(cafe$vessel, cafe$vessel),
    breaks = cafe$vessel,
    guide = guide_legend(
      override.aes = list(
        fill = c("#1B0C42", "#59106E", "#9B2964", "#D74B3F", "#F88A0C", "#F7D441")
      ),
      nrow = 2, keyheight = unit(2, "lines"), default.unit = "line"
    )
  ) +
  scale_fill_viridis_c(
    limits = c(0, 100), begin = 0.04, end = 0.94, option = "inferno",
    guide = "none"
  ) +
  scale_x_continuous(limits = c(0.35, 6.65), expand = expansion(mult = 0)) +
  scale_y_continuous(limits = c(0.55, 1.65), expand = expansion(mult = 0)) +
  labs(title = "Coffee and autumn; continuous fill, independent outline colour") +
  theme_void() +
  theme(legend.position = "bottom")

