---
title: "Getting started with prakriti"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Getting started with prakriti}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

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

## What is prakriti?

**prakriti** (Sanskrit for *nature*) gives you 30 color palettes pulled from
Indian landscapes. Each one is built for a specific job - sequential for
ordered data, diverging for data with a midpoint, qualitative for categories -
and they all plug straight into `ggplot2`.

```{r load}
library(prakriti)
library(ggplot2)
```

## Finding your way around

`prakriti_names()` lists every palette. `prakriti_info()` gives you the full
picture - name, type, number of colors, and what landscape inspired it.

```{r discover}
prakriti_names()
prakriti_info()
```

Filter by type if you know what kind of data you're working with:

```{r filter}
info <- prakriti_info()
info[info$type == "diverging", ]
```

## Pulling colors

`prakriti_palette()` returns a character vector of hex codes. By default you
get the full palette. Pass `n` to grab a subset.

```{r pull}
prakriti_palette("thar")
prakriti_palette("himalaya", n = 3)
```

Reverse any palette with `direction = -1`:

```{r reverse}
prakriti_palette("chinar", direction = -1)
```

Need more colors than the palette has? Interpolate smoothly:

```{r continuous}
prakriti_palette("nilgiri", n = 15, type = "continuous")
```

## Viewing palettes

Single palette:

```{r display-one, fig.height = 1.5}
display_prakriti("valley_of_flowers")
```

The whole collection (make your plot pane tall):

```{r display-all, fig.height = 14}
display_prakriti()
```

## Using with ggplot2

Qualitative palettes default to discrete scales. Sequential and diverging
default to continuous. You can override with `discrete = TRUE` or `FALSE`.

```{r scatter, fig.height = 4}
ggplot(iris, aes(Sepal.Length, Petal.Length,
                 color = Species, shape = Species)) +
  geom_point(size = 3, alpha = 0.85) +
  scale_color_prakriti("valley_of_flowers") +
  labs(title = "Iris measurements",
       x = "Sepal length (cm)", y = "Petal length (cm)") +
  theme_minimal()
```

```{r heatmap}
ggplot(faithfuld, aes(waiting, eruptions, fill = density)) +
  geom_raster(interpolate = TRUE) +
  scale_fill_prakriti("himalaya") +
  coord_cartesian(expand = FALSE) +
  labs(title = "Old Faithful eruption density") +
  theme_minimal()
```

```{r boxplot, fig.height = 4}
ggplot(mtcars, aes(factor(cyl), mpg, fill = factor(cyl))) +
  geom_boxplot() +
  scale_fill_prakriti("thar", discrete = TRUE) +
  labs(title = "MPG by cylinder count", x = "Cylinders", y = "MPG") +
  theme_minimal() +
  theme(legend.position = "none")
```

## What's next

- [Palette gallery](gallery.html) - all 30 palettes as swatches, continuous
  ramps, and a full metadata table
- [Sequential & diverging recipes](sequential-diverging.html) - heatmaps,
  contours, correlation tiles, calendar charts, temperature anomaly maps
- [Qualitative recipes](qualitative.html) - scatter plots, stacked areas,
  grouped bars, donut charts, ridgelines, dark-mode density plots
