Skip to content

Commit 1aed230

Browse files
committed
conditional evaluation of ggforce chunks (only if package is available)
1 parent 77833e3 commit 1aed230

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

intermediate_ggplot2.qmd

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ different aspects of adjusting `ggplot` objects.
2525
# Load packages
2626

2727
```{r}
28+
# check if problematic packages are available
29+
ggforce_available <- require(ggforce, quietly = TRUE)
30+
2831
suppressPackageStartupMessages({
2932
## data manipulation
3033
library(scales)
@@ -33,7 +36,9 @@ suppressPackageStartupMessages({
3336
library(tidyr)
3437
## ggplot2 + extension packages
3538
library(ggplot2)
36-
library(ggforce)
39+
if (ggforce_available) {
40+
library(ggforce)
41+
}
3742
library(ggalt)
3843
library(ggridges)
3944
library(GGally)
@@ -320,6 +325,7 @@ Finally, the `facet_row` function from the `ggforce` package lets us adjust
320325
the space allocated to each facet and at the same time use a free y-axis.
321326

322327
```{r, fig.width = 10}
328+
#| eval: !expr ggforce_available
323329
ggplot(vehicles, aes(x = fct_lump_n(make, n = 3))) +
324330
geom_bar() +
325331
facet_row(~ fct_lump_n(fuel, n = 3, other_level = "Other"),
@@ -672,6 +678,7 @@ them in an ellipse (`ggforce::geom_mark_circle`) or a polygon
672678
(`ggalt::geom_encircle`):
673679

674680
```{r}
681+
#| eval: !expr ggforce_available
675682
## ggforce
676683
ggplot(vehicles %>% dplyr::filter(year == 2005), aes(x = hwy, y = cty)) +
677684
geom_point() +
@@ -680,7 +687,9 @@ ggplot(vehicles %>% dplyr::filter(year == 2005), aes(x = hwy, y = cty)) +
680687
filter = (cty - hwy) > 1),
681688
fill = "pink") +
682689
ggp
690+
```
683691

692+
```{r}
684693
## ggalt
685694
ggplot(iris, aes(x = Petal.Width, y = Sepal.Width, colour = Species)) +
686695
geom_point() +

0 commit comments

Comments
 (0)