@@ -27,6 +27,8 @@ different aspects of adjusting `ggplot` objects.
2727``` {r}
2828# check if problematic packages are available
2929ggforce_available <- require(ggforce, quietly = TRUE)
30+ ggrastr_available <- require(ggrastr, quietly = TRUE)
31+ ggiraph_available <- require(ggiraph, quietly = TRUE)
3032
3133suppressPackageStartupMessages({
3234 ## data manipulation
@@ -48,15 +50,19 @@ suppressPackageStartupMessages({
4850 library(ggrepel)
4951 library(ggtext)
5052 library(ggnewscale)
51- library(ggrastr)
53+ if (ggrastr_available) {
54+ library(ggrastr)
55+ }
5256 library(scattermore)
5357 library(directlabels)
5458 ## packages to combine multiple figures
5559 library(patchwork)
5660 library(cowplot)
5761 ## packages for interactive graphics
5862 library(plotly)
59- library(ggiraph)
63+ if (ggiraph_available) {
64+ library(ggiraph)
65+ }
6066 ## color packages
6167 library(RColorBrewer)
6268 library(circlize)
@@ -489,6 +495,7 @@ raster just the problematic layer, while keeping the remaining layers as vectors
489495for example using the ` geom_point_rast ` function:
490496
491497``` {r, fig.width=9}
498+ #| eval: !expr ggrastr_available
492499## ggrastr::geom_*_rastr layers
493500p1 <- ggplot(diamonds, aes(carat, price)) +
494501 geom_point_rast(size = 0.2, raster.dpi = 200) +
@@ -503,6 +510,7 @@ The resolution of the raster images can be controlled with `dpi` (or `raster.dpi
503510above):
504511
505512``` {r, fig.width=9}
513+ #| eval: !expr ggrastr_available
506514## ggrastr::rasterise() wrapper
507515## ... around the whole plot
508516p2 <- rasterise(p1, layers = c("Point", "Title")) # raster all layers of given types
@@ -629,6 +637,7 @@ Another option for making interactive graphs is to use the `ggiraph` package,
629637which provides dedicated interactive layers.
630638
631639``` {r}
640+ #| eval: !expr ggiraph_available
632641girafe(ggobj = ggplot(vehicles) +
633642 geom_point_interactive(aes(x = hwy, y = cty,
634643 tooltip = make, data_id = make)) +
0 commit comments