---
title: Facets
---

```{r}
library(gglite)
```

Faceting splits data into multiple panels. gglite supports rectangular and
circular faceting.

## Rectangular Facet (by x)

```{r}
g2(iris, Sepal.Length ~ Sepal.Width) |>
  facet_rect(~ Species)
```

## Rectangular Facet (by y)

```{r}
g2(iris, Sepal.Length ~ Sepal.Width) |>
  facet_rect(y = ~ Species)
```

## Rectangular Facet (by x and y)

```{r}
df = data.frame(
  x = rnorm(200), y = rnorm(200),
  a = sample(c('A', 'B'), 200, replace = TRUE),
  b = sample(c('X', 'Y'), 200, replace = TRUE)
)
g2(df, y ~ x) |>
  facet_rect(b ~ a)
```

## Facet with color

```{r}
g2(iris, Sepal.Length ~ Sepal.Width, color = ~ Species) |>
  facet_rect(~ Species)
```

## Circular Facet

```{r}
g2(iris, Sepal.Length ~ Sepal.Width) |>
  facet_circle(position = ~ Species)
```
