---
title: "Palette gallery"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Palette gallery}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.width = 8,
  fig.height = 14,
  dpi = 96
)
```

All 30 palettes at a glance. Use this page to pick the right one for your plot.

## Swatch grid

```{r grid, fig.height = 14}
library(prakriti)
display_prakriti()
```

## Faceted poster

A ggplot2 version, handy if you want to save it as a PNG or drop it into a
slide deck.

```{r poster, fig.height = 12, fig.width = 8}
library(ggplot2)

gallery_df <- do.call(rbind, lapply(prakriti_names(), function(nm) {
  pal <- prakriti_palettes[[nm]]
  data.frame(
    palette = nm,
    type    = pal$type,
    pos     = seq_along(pal$colors),
    color   = pal$colors,
    stringsAsFactors = FALSE
  )
}))
gallery_df$palette <- factor(gallery_df$palette, levels = prakriti_names())

ggplot(gallery_df, aes(x = pos, y = 1, fill = color)) +
  geom_tile(height = 0.9) +
  scale_fill_identity() +
  facet_wrap(~ palette, ncol = 5, strip.position = "top") +
  labs(
    title    = "prakriti - 30 palettes from India's natural landscapes",
    subtitle = "Sequential | Diverging | Qualitative"
  ) +
  theme_void(base_size = 11) +
  theme(
    plot.title    = element_text(face = "bold", hjust = 0, size = rel(1.3),
                                 margin = margin(b = 4)),
    plot.subtitle = element_text(hjust = 0, color = "grey30",
                                 margin = margin(b = 12)),
    strip.text    = element_text(face = "bold", size = rel(0.8),
                                 margin = margin(b = 2)),
    plot.margin   = margin(16, 16, 16, 16)
  )
```

## Continuous ramps

Sequential and diverging palettes interpolated to 80 stops, so you can see
how they look as smooth gradients.

```{r ramps, fig.height = 10, fig.width = 8}
seq_div <- prakriti_info()
seq_div <- seq_div[seq_div$type != "qualitative", ]

ramp_df <- do.call(rbind, lapply(seq_div$name, function(nm) {
  cols <- prakriti_palette(nm, n = 80, type = "continuous")
  data.frame(
    palette = nm,
    pos     = seq_along(cols),
    color   = cols,
    stringsAsFactors = FALSE
  )
}))
ramp_df$palette <- factor(ramp_df$palette, levels = seq_div$name)

ggplot(ramp_df, aes(pos, 1, fill = color)) +
  geom_tile() +
  scale_fill_identity() +
  facet_wrap(~ palette, ncol = 3, strip.position = "top") +
  labs(title = "Continuous interpolation (80 stops)") +
  theme_void(base_size = 11) +
  theme(
    plot.title = element_text(face = "bold", margin = margin(b = 10)),
    strip.text = element_text(face = "bold", size = rel(0.85),
                               margin = margin(b = 2)),
    plot.margin = margin(12, 12, 12, 12)
  )
```

## Palette metadata

```{r table}
knitr::kable(prakriti_info(), row.names = FALSE)
```
