Skip to content

Commit f64d08a

Browse files
committed
Clarify docs, add vignette
1 parent 1d794c8 commit f64d08a

File tree

7 files changed

+103
-2
lines changed

7 files changed

+103
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.Rproj.user
22
docs
33
.Rhistory
4+
inst/doc

DESCRIPTION

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Roxygen: list(markdown = TRUE)
1414
RoxygenNote: 7.3.1
1515
Depends: R (>= 4.3)
1616
Suggests:
17+
rmarkdown,
1718
spelling,
1819
testthat (>= 3.0.0),
1920
withr
@@ -30,3 +31,4 @@ Imports:
3031
vctrs
3132
URL: https://billdenney.github.io/ggtibble/
3233
Language: en-US
34+
VignetteBuilder: knitr

inst/WORDLIST

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
CMD
22
Codecov
33
Tibbles
4+
geoms
45
gg
56
gglist
67
ggplot

man/ggtibble.Rd

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/knit_print.gglist.Rd

Lines changed: 7 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vignettes/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
*.html
2+
*.R

vignettes/v01-introduction.Rmd

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
---
2+
title: "Introduction to 'ggtibble'"
3+
output: rmarkdown::html_vignette
4+
vignette: >
5+
%\VignetteIndexEntry{Introduction to 'ggtibble'}
6+
%\VignetteEngine{knitr::rmarkdown}
7+
%\VignetteEncoding{UTF-8}
8+
---
9+
10+
```{r, include = FALSE}
11+
knitr::opts_chunk$set(
12+
collapse = TRUE,
13+
comment = "#>"
14+
)
15+
```
16+
17+
```{r setup}
18+
library(ggtibble)
19+
```
20+
21+
# Motivation for `ggtibble`
22+
23+
From time to time, having a list of ggplots and being able to work on them like
24+
a regular ggplot can be very helpful. For example, when writing a report, you
25+
may want to make a set of figures to separate out various levels of a group,
26+
then make separate figures for each group.
27+
28+
# Introduction
29+
30+
The `ggtibble` package has two main functions to create sets of figures,
31+
`ggtibble()` and `gglist()`. These create a tibble with optional labels per
32+
figure and captions (for `ggtibble()`) or a simpler list of figures (for
33+
`gglist()`).
34+
35+
Both `ggtibble` and `gglist` objects can have ggplot geoms, facets, labels, and
36+
lists of those added to them as though they were normal ggplot objects. And,
37+
you can add a `gglist` to either a `ggtibble` or a `gglist`.
38+
39+
# Typical use
40+
41+
Typical use will load required libraries, setup your plot data, generate the
42+
plot, and then `knit_print()` it.
43+
44+
When generating the plot:
45+
46+
1. Give your dataset,
47+
2. Indicate your columns for plotting using the `aes()` mapping as for any ggplot2 object,
48+
3. Provide the `outercols` which are columns outside your dataset; one plot will
49+
be generated for each unique level of your data with the `outercols`. Note
50+
that you cannot use `outercols` columns within the plot, but you will use
51+
them for captions and labels.
52+
4. You can give a `caption` with a `glue::glue_data()` specification where valid
53+
columns are any column names that are in your `outercols` specification. (If
54+
you don't give a caption, then it will be an empty string, `""`.)
55+
5. You can give a list of labels which are each processed the same as the
56+
caption via `glue::glue_data()` and then passed to `labs()`.
57+
6. After the plot is setup in ways that are specific to `ggtibble`, use it like
58+
a normal ggplot object adding geoms, etc.
59+
60+
```{r typical, fig.cap=all_plots$caption}
61+
# Note, add `fig.cap=all_plots$caption` to show the generated caption for the
62+
# figures
63+
64+
library(ggtibble)
65+
library(dplyr)
66+
library(ggplot2)
67+
68+
d_plot <-
69+
mtcars |>
70+
mutate(
71+
dispu = "cu. in."
72+
)
73+
all_plots <-
74+
ggtibble(
75+
d_plot,
76+
aes(x = disp, y = hp),
77+
outercols = c("cyl", "dispu"),
78+
caption = "Horsepower by displacement for {cyl} cars",
79+
labs = list(x = "Displacement ({dispu})", y = "Gross horsepower")
80+
) +
81+
geom_point() +
82+
geom_line()
83+
84+
# The result is a tibble with columns for the `data_plot`, `figure`, and
85+
# `caption`
86+
as_tibble(all_plots)
87+
88+
# You can then show all the figures with the `knit_print()` method.
89+
knit_print(all_plots)
90+
```

0 commit comments

Comments
 (0)