Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions html/data-visualization.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -519,22 +519,22 @@ Facets divide a plot into subplots based on the values of one or more discrete v
t <- ggplot(mpg, aes(cty, hwy)) + geom_point()
```

- `t + facet_grid(. ~ fl)`: Facet into a column based on fl.
- `t + facet_grid(cols = vars(fl))`: Facet into a column based on fl.

- `t + facet_grid(year ~ .)`: Facet into rows based on year.
- `t + facet_grid(rows = vars(year))`: Facet into rows based on year.

- `t + facet_grid(year ~ fl)`: Facet into both rows and columns.
- `t + facet_grid(rows = vars(year), cols = vars(fl))`: Facet into both rows and columns.

- `t + facet_wrap(~ fl)`: Wrap facets into a rectangular layout.
- `t + facet_wrap(facets = vars(fl))`: Wrap facets into a rectangular layout.

- `t + facet_grid(drv ~ fl, scales = "free")`: Set **scales** to let axis limits vary across facets.
- `t + facet_grid(rows = vars(drv), cols = vars(fl), scales = "free")`: Set **scales** to let axis limits vary across facets.
Also `"free_x"` for x axis limits adjust to individual facets and `"free_y"` for y axis limits adjust to individual facets.

Set **labeller** to adjust facet label:

- `t + facet_grid(. ~ fl, labeller = label_both)`: Labels each facet as "fl: c", "fl: d", etc.
- `t + facet_grid(cols = vars(fl), labeller = label_both)`: Labels each facet as "fl: c", "fl: d", etc.

- `t + facet_grid(fl ~ ., labeller = label_bquote(alpha ^ .(fl)))`: Labels each facet as "𝛼^c^", "𝛼^d^", etc.
- `t + facet_grid(rows = vars(fl), labeller = label_bquote(alpha ^ .(fl)))`: Labels each facet as "𝛼^c^", "𝛼^d^", etc.

## Labels and Legends

Expand Down Expand Up @@ -580,4 +580,4 @@ Updated: `r format(Sys.Date(), "%Y-%m")`.
packageVersion("ggplot2")
```

------------------------------------------------------------------------
------------------------------------------------------------------------