Skip to content

Commit

Permalink
reduce vignette sizes on CRAN
Browse files Browse the repository at this point in the history
  • Loading branch information
mjskay committed Nov 26, 2023
1 parent 220e6e4 commit 429ab02
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 183 deletions.
1 change: 1 addition & 0 deletions vignettes/.install_extras
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
^children
39 changes: 39 additions & 0 deletions vignettes/children/chunk_options.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<style type="text/css">
.kable-table table {
margin-left: 0;
}
img {
border: none;
}
</style>

```{r chunk_options, include=FALSE}
if (requireNamespace("pkgdown", quietly = TRUE) && pkgdown::in_pkgdown()) {
tiny_width = 5.5
tiny_height = 3 + 2/3
small_width = med_width = 6.75
small_height = med_height = 4.5
large_width = 8
large_height = 5.25
} else {
tiny_width = 5
tiny_height = 3 + 1/3
small_width = 5
small_height = 3 + 1/3
med_width = 5.5
med_height = 3 + 2/3
large_width = 6
large_height = 4
}

knitr::opts_chunk$set(
fig.width = small_width,
fig.height = small_height
)
if (capabilities("cairo") && Sys.info()[['sysname']] != "Darwin") {
knitr::opts_chunk$set(
dev = "png",
dev.args = list(type = "cairo")
)
}
```
70 changes: 22 additions & 48 deletions vignettes/dotsinterval.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,7 @@ vignette: >
%\VignetteEncoding{UTF-8}
---

<style type="text/css">
.kable-table table {
margin-left: 0;
}
img {
border: none;
}
</style>

```{r chunk_options, include=FALSE}
tiny_width = 5.5
tiny_height = 3 + 2/3
small_width = med_width = 6.75
small_height = med_height = 4.5
large_width = 8
large_height = 5.25
knitr::opts_chunk$set(
fig.width = small_width,
fig.height = small_height
)
if (capabilities("cairo") && Sys.info()[['sysname']] != "Darwin") {
knitr::opts_chunk$set(
dev = "png",
dev.args = list(type = "cairo")
)
}
```{r, child="children/chunk_options.txt"}
```

## Introduction
Expand Down Expand Up @@ -407,7 +381,7 @@ When `side` is `"both"`, these layouts look like this:
Thus, it is possible to create beeswarm plots by using `geom_dots()`
with `side = "both"`:

```{r beeswarm_bin}
```{r beeswarm_bin, fig.width = small_width, fig.height = small_height}
set.seed(1234)
abc_df = data.frame(
Expand All @@ -424,7 +398,7 @@ abc_df %>%
`side = "both"` also tends to work well with the `"hex"` and `"swarm"` layouts for
more classic-looking "beeswarm" plots:

```{r beeswarm_hex}
```{r beeswarm_hex, fig.width = small_width, fig.height = small_height}
abc_df %>%
ggplot(aes(x = abc, y = value)) +
geom_dots(side = "both", layout = "hex", stackratio = 0.92) +
Expand All @@ -433,7 +407,7 @@ abc_df %>%

And with `"swarm"`:

```{r beeswarm}
```{r beeswarm, fig.width = small_width, fig.height = small_height}
abc_df %>%
ggplot(aes(x = abc, y = value)) +
geom_dots(side = "both", layout = "swarm") +
Expand All @@ -448,7 +422,7 @@ which use the `"swarm"` and `"weave"` layouts respectively. These also use
`side = "both"`, and are intended to make it easy to create good-looking beeswarm
plots *without* manually tweaking settings:

```{r geom_weave}
```{r geom_weave, fig.width = small_width, fig.height = small_height}
set.seed(1234)
swarm_data = data.frame(
Expand All @@ -458,12 +432,12 @@ swarm_data = data.frame(
swarm_plot = swarm_data %>%
ggplot(aes(x = g, y = y)) +
geom_swarm(linewidth = 0) +
geom_swarm(linewidth = 0, alpha = 0.75) +
labs(title = "geom_swarm()")
weave_plot = swarm_data %>%
ggplot(aes(x = g, y = y)) +
geom_weave(linewidth = 0) +
geom_weave(linewidth = 0, alpha = 0.75) +
labs(title = "geom_weave()")
swarm_plot + weave_plot
Expand All @@ -476,7 +450,7 @@ For example, we can vary the `fill` aesthetic to create two
subgroups, and use `position = "dodge"` to dodge entire "swarms" at once so
the subgroups do not overlap:

```{r beeswarm_dodge}
```{r beeswarm_dodge, fig.width = small_width, fig.height = small_height}
set.seed(12345)
abcc_df = data.frame(
Expand All @@ -487,7 +461,7 @@ abcc_df = data.frame(
abcc_df %>%
ggplot(aes(y = value, x = abc, fill = hi)) +
geom_weave(position = "dodge", linewidth = 0) +
geom_weave(position = "dodge", linewidth = 0, alpha = 0.75) +
scale_color_brewer(palette = "Dark2") +
ggtitle(
'geom_weave(position = "dodge")',
Expand All @@ -503,10 +477,10 @@ numbers from `0:24`, are supported) and using the `color` aesthetic.

For example, we can vary `shape` and `color` simultaneously:

```{r beeswarm_shape_color}
```{r beeswarm_shape_color, fig.width = small_width, fig.height = small_height}
abcc_df %>%
ggplot(aes(y = value, x = abc, shape = abc, color = hi)) +
geom_weave(position = "dodge") +
geom_weave(position = "dodge", alpha = 0.75) +
scale_color_brewer(palette = "Dark2") +
ggtitle(
'geom_weave(position = "dodge")',
Expand All @@ -526,7 +500,7 @@ dots in data order within the layout but allow aesthetics to vary across them.

For example:

```{r beeswarm_shape_color_together}
```{r beeswarm_shape_color_together, fig.width = small_width, fig.height = small_height}
abcc_df %>%
ggplot(aes(y = value, x = abc, fill = hi, group = NA)) +
geom_dots(linewidth = 0) +
Expand All @@ -543,7 +517,7 @@ override this by passing a variable to the `order` aesthetic, which will set
the sort order within bins. This can be used to create "stacked" dotplots by
setting `order` to a discrete variable:

```{r beeswarm_shape_color_together_stacked}
```{r beeswarm_shape_color_together_stacked, fig.width = small_width, fig.height = small_height}
abcc_df %>%
ggplot(aes(y = value, x = abc, fill = hi, group = NA, order = hi)) +
geom_dots(linewidth = 0) +
Expand All @@ -560,7 +534,7 @@ Continuous variables can also be varied within groups. Since continuous variable
will not automatically set the `group` aesthetic, we can simply assign them to
the desired aesthetic we want to vary:

```{r beeswarm_shape_color_continuous}
```{r beeswarm_shape_color_continuous, fig.width = small_width, fig.height = small_height}
abcc_df %>%
arrange(hi) %>%
ggplot(aes(y = value, x = abc, shape = abc, color = value)) +
Expand Down Expand Up @@ -648,7 +622,7 @@ the bounds of the distribution. Otherwise, the dotplot will be smoothed incorrec
For example, on a Beta(0.5, 0.5) distribution, which is bounded between 0 and 1,
we should use `smooth = smooth_bounded(bounds = c(0, 1))`:

```{r smooth_bounded_versus_unbounded}
```{r smooth_bounded_versus_unbounded, fig.width = small_width, fig.height = small_height}
set.seed(1234)
x = rbeta(2000, 0.5, 0.5)
Expand Down Expand Up @@ -761,7 +735,7 @@ accept specifications for distributions in one of two ways:

For example, here are a variety of distributions:

```{r dotsinterval_dist}
```{r dotsinterval_dist, fig.width = small_width, fig.height = small_height}
dist_df = tibble(
dist = c(dist_normal(1,0.25), dist_beta(3,3), dist_gamma(5,5)),
dist_name = format(dist)
Expand All @@ -782,7 +756,7 @@ referred to as a *quantile dotplot*, which can help people make better decisions
This can be changed using the `quantiles` argument. For example, we can plot the same
distributions again, now with 1000 quantiles:

```{r dotsinterval_dist_1000}
```{r dotsinterval_dist_1000, fig.width = small_width, fig.height = small_height}
dist_df %>%
ggplot(aes(y = dist_name, xdist = dist)) +
stat_dotsinterval(quantiles = 1000, point_interval = mode_hdci) +
Expand All @@ -802,7 +776,7 @@ and correspond to the smallest interval containing that dot. We can use these
to color dots according to the interval containing them (we'll also use the
`"weave"` layout since it maintains x positions better than the `"bin"` layout):

```{r dotsinterval_dist_1000_level_color}
```{r dotsinterval_dist_1000_level_color, fig.width = small_width, fig.height = small_height}
dist_df %>%
ggplot(aes(y = dist_name, xdist = dist, slab_fill = after_stat(level))) +
stat_dotsinterval(quantiles = 1000, point_interval = mode_hdci, layout = "weave", slab_color = NA) +
Expand Down Expand Up @@ -830,7 +804,7 @@ aesthetics.
Thus, because it relies upon generated variables from the stat, you can use the
`after_stat()` or `stage()` functions from `ggplot2` to map those variables. For example:

```{r dotsinterval_dist_color}
```{r dotsinterval_dist_color, fig.width = small_width, fig.height = small_height}
dist_df %>%
ggplot(aes(y = dist_name, xdist = dist, slab_color = after_stat(x))) +
stat_dotsinterval(slab_shape = 19, quantiles = 500) +
Expand All @@ -857,7 +831,7 @@ color aesthetics).
Another potentially useful application of post-stat aesthetic computation is to
apply thresholds on a dotplot, coloring points on one side of a line differently:

```{r dist_dots_shape_color, fig.width = med_width, fig.height = med_height}
```{r dist_dots_shape_color, fig.width = small_width, fig.height = small_height}
ab_df = tibble(
ab = c("a", "b"),
mean = c(5, 7),
Expand Down Expand Up @@ -885,7 +859,7 @@ side of a cutoff when coloring dots within dotplots. Thus it can be useful to us
`"weave"` or `"swarm"` layouts, which tend to position dots closer to their true
`x` positions, rather than at bin centers:

```{r dist_dots_weave, fig.width = med_width, fig.height = med_height}
```{r dist_dots_weave, fig.width = small_width, fig.height = small_height}
ab_df %>%
ggplot(aes(y = ab, xdist = dist_normal(mean, sd), fill = after_stat(x < 6))) +
stat_dots(position = "dodge", color = NA, layout = "weave") +
Expand Down Expand Up @@ -916,7 +890,7 @@ the total area of its corresponding dotplot).
We'll use a subsample of of the data to show how it might look on a reasonably-sized
dataset.

```{r halfeye_dotplot}
```{r halfeye_dotplot, fig.width = small_width, fig.height = small_height}
set.seed(12345) # for reproducibility
data.frame(
Expand Down
44 changes: 9 additions & 35 deletions vignettes/freq-uncertainty-vis.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,8 @@ vignette: >
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---

<style type="text/css">
.kable-table table {
margin-left: 0;
}
img {
border: none;
}
</style>

```{r chunk_options, include=FALSE}
tiny_width = 5.5
tiny_height = 3 + 2/3
small_width = med_width = 6.75
small_height = med_height = 4.5
large_width = 8
large_height = 5.25
knitr::opts_chunk$set(
fig.width = small_width,
fig.height = small_height
)
if (capabilities("cairo") && Sys.info()[['sysname']] != "Darwin") {
knitr::opts_chunk$set(
dev = "png",
dev.args = list(type = "cairo")
)
}

```{r, child="children/chunk_options.txt"}
```

## Introduction
Expand Down Expand Up @@ -131,7 +105,7 @@ The `stat_slabinterval()` family of functions supports these objects.

Putting everything together, we have:

```{r halfeye}
```{r halfeye, fig.width = tiny_width, fig.height = tiny_height}
m_ABC %>%
tidy() %>%
ggplot(aes(y = term)) +
Expand All @@ -154,7 +128,7 @@ With:

Putting everything together, we have:

```{r halfeye_with_data}
```{r halfeye_with_data, fig.width = tiny_width, fig.height = tiny_height}
ABC %>%
data_grid(condition) %>%
augment(m_ABC, newdata = ., se_fit = TRUE) %>%
Expand All @@ -170,7 +144,7 @@ ABC %>%

Of course, this works with the entire `stat_slabinterval()` family. Here are gradient plots instead:

```{r gradientinterval}
```{r gradientinterval, fig.width = tiny_width, fig.height = tiny_height}
ABC %>%
data_grid(condition) %>%
augment(m_ABC, newdata = ., se_fit = TRUE) %>%
Expand All @@ -187,7 +161,7 @@ discussion in the section on gradient plots in `vignette("slabinterval")`.

Or complementary cumulative distribution function (CCDF) bar plots:

```{r ccdfinterval}
```{r ccdfinterval, fig.width = tiny_width, fig.height = tiny_height}
ABC %>%
data_grid(condition) %>%
augment(m_ABC, newdata = ., se_fit = TRUE) %>%
Expand All @@ -199,7 +173,7 @@ ABC %>%

We can also create quantile dotplots by using the `dots` family of geoms. Quantile dotplots show quantiles from a distribution (in this case, the sampling distribution), employing a *frequency framing* approach to uncertainty communication that can be easier for people to interpret ([Kay et al. 2016](https://doi.org/10.1145/2858036.2858558), [Fernandes et al. 2018](https://doi.org/10.1145/3173574.3173718)):

```{r dotplot}
```{r dotplot, fig.width = tiny_width, fig.height = tiny_height}
ABC %>%
data_grid(condition) %>%
augment(m_ABC, newdata = ., se_fit = TRUE) %>%
Expand All @@ -222,7 +196,7 @@ m_mpg = lm(mpg ~ hp * cyl, data = mtcars)

Again we'll use `modelr::data_grid()` with `broom::tidy()`, but now we'll employ `stat_lineribbon()`:

```{r lineribbon}
```{r lineribbon, fig.width = tiny_width, fig.height = tiny_height}
mtcars %>%
group_by(cyl) %>%
data_grid(hp = seq_range(hp, n = 101)) %>%
Expand Down Expand Up @@ -250,7 +224,7 @@ Here we'll "whiten" the fill color of each band according to its `level` (the `l
variable is computed by `stat_lineribbon()` and is an ordered factor version of
`.width`):

```{r lineribbon_lightened}
```{r lineribbon_lightened, fig.width = tiny_width, fig.height = tiny_height}
mtcars %>%
group_by(cyl) %>%
data_grid(hp = seq_range(hp, n = 101)) %>%
Expand Down
Loading

0 comments on commit 429ab02

Please sign in to comment.