diff --git a/DESCRIPTION b/DESCRIPTION index 8cb45db..3ca09e1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: gridpattern Type: Package Title: 'grid' Pattern Grobs -Version: 1.2.0-2 +Version: 1.2.0-3 Authors@R: c(person("Mike", "FC", role = "aut", comment = "Code/docs adapted from ggpattern"), person("Trevor L.", "Davis", role=c("aut", "cre"), email="trevor.l.davis@gmail.com", comment = c(ORCID = "0000-0001-6341-4639")), diff --git a/R/alphaMaskGrob.R b/R/alphaMaskGrob.R index ce6de6f..008bea5 100644 --- a/R/alphaMaskGrob.R +++ b/R/alphaMaskGrob.R @@ -33,9 +33,9 @@ #' id = rep(1:2, each = 7), #' rule = "evenodd", gp = gp) #' masked <- alphaMaskGrob(maskee, masker, use_R4.1_masks = FALSE) -#' grid.newpage() #' grid.draw(masked) -#' +#' } +#' if (capabilities("png") && require("grid")) { #' maskee_transparent <- rectGrob(gp = gpar(col = NA, fill = "blue")) #' gp <- gpar(lwd = 20, col = "black", fill = grDevices::rgb(0, 0, 0, 0.5)) #' masker_transparent <- editGrob(masker, gp = gp) diff --git a/R/grid-pattern.R b/R/grid-pattern.R index 5711f02..fc1f66e 100644 --- a/R/grid-pattern.R +++ b/R/grid-pattern.R @@ -62,51 +62,51 @@ #' @examples #' print(names_pattern) #' \donttest{ # Once took more >10s on a CRAN autocheck -#' if (require("grid")) { -#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) -#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) #' -#' # geometry-based patterns -#' # 'stripe' pattern -#' grid.newpage() -#' grid.pattern("stripe", x_hex, y_hex, -#' colour="black", fill=c("yellow", "blue"), density = 0.5) +#' # geometry-based patterns +#' # 'stripe' pattern +#' grid::grid.newpage() +#' grid.pattern("stripe", x_hex, y_hex, +#' colour="black", fill=c("yellow", "blue"), density = 0.5) #' -#' # Can alternatively use "gpar()" to specify colour and line attributes -#' grid.newpage() -#' grid.pattern("stripe", x_hex, y_hex, gp = gpar(col="blue", fill="red", lwd=2)) +#' # Can alternatively use "gpar()" to specify colour and line attributes +#' grid::grid.newpage() +#' grid.pattern("stripe", x_hex, y_hex, +#' gp = grid::gpar(col="blue", fill="red", lwd=2)) #' -#' # 'weave' pattern -#' grid.newpage() -#' grid.pattern("weave", x_hex, y_hex, type = "satin", -#' colour = "black", fill = "lightblue", fill2 = "yellow", -#' density = 0.3) +#' # 'weave' pattern +#' grid::grid.newpage() +#' grid.pattern("weave", x_hex, y_hex, type = "satin", +#' colour = "black", fill = "lightblue", fill2 = "yellow", +#' density = 0.3) #' -#' # 'regular_polygon' pattern -#' grid.newpage() -#' grid.pattern_regular_polygon(x_hex, y_hex, colour = "black", -#' fill = c("blue", "yellow", "red"), -#' shape = c("convex4", "star8", "circle"), -#' density = c(0.45, 0.42, 0.4), -#' spacing = 0.08, angle = 0) +#' # 'regular_polygon' pattern +#' grid::grid.newpage() +#' grid.pattern_regular_polygon(x_hex, y_hex, colour = "black", +#' fill = c("blue", "yellow", "red"), +#' shape = c("convex4", "star8", "circle"), +#' density = c(0.45, 0.42, 0.4), +#' spacing = 0.08, angle = 0) #' -#' # can be used to achieve a variety of 'tiling' effects -#' grid.newpage() -#' grid.pattern_regular_polygon(x_hex, y_hex, color = "transparent", -#' fill = c("white", "grey", "black"), -#' density = 1.0, spacing = 0.1, -#' shape = "convex6", grid = "hex") -#' if (require("magick")) { -#' # array-based patterns -#' # 'image' pattern -#' logo_filename <- system.file("img", "Rlogo.png" , package="png") -#' grid.newpage() -#' grid.pattern("image", x_hex, y_hex, filename=logo_filename, type="fit") -#' -#' # 'plasma' pattern -#' grid.newpage() -#' grid.pattern("plasma", x_hex, y_hex, fill="green") -#' } +#' # can be used to achieve a variety of 'tiling' effects +#' grid::grid.newpage() +#' grid.pattern_regular_polygon(x_hex, y_hex, color = "transparent", +#' fill = c("white", "grey", "black"), +#' density = 1.0, spacing = 0.1, +#' shape = "convex6", grid = "hex") +#' if (suppressPackageStartupMessages(requireNamespace("magick", quietly = TRUE))) { +#' # array-based patterns +#' # 'image' pattern +#' logo_filename <- system.file("img", "Rlogo.png" , package="png") +#' grid::grid.newpage() +#' grid.pattern("image", x_hex, y_hex, filename=logo_filename, type="fit") +#' } +#' if (suppressPackageStartupMessages(requireNamespace("magick", quietly = TRUE))) { +#' # 'plasma' pattern +#' grid::grid.newpage() +#' grid.pattern("plasma", x_hex, y_hex, fill="green") #' } #' } #' @seealso \url{https://coolbutuseless.github.io/package/ggpattern/index.html} diff --git a/R/pattern-array-ambient.R b/R/pattern-array-ambient.R index edc7a74..a633dc7 100644 --- a/R/pattern-array-ambient.R +++ b/R/pattern-array-ambient.R @@ -8,10 +8,12 @@ #' @inheritParams ambient::noise_worley #' @return A grid grob object invisibly. If `draw` is `TRUE` then also draws to the graphic device as a side effect. #' @examples -#' if (requireNamespace("ambient")) { +#' if (requireNamespace("ambient", quietly = TRUE)) { #' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) #' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) #' grid.pattern_ambient(x_hex, y_hex, fill = "green", fill2 = "blue") +#' } +#' if (requireNamespace("ambient")) { #' grid::grid.newpage() #' grid.pattern_ambient(x_hex, y_hex, fill = "green", fill2 = "blue", type = "cubic") #' } diff --git a/R/pattern-array-image.R b/R/pattern-array-image.R index 5277266..5c019a3 100644 --- a/R/pattern-array-image.R +++ b/R/pattern-array-image.R @@ -27,7 +27,8 @@ #' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) #' logo_filename <- system.file("img", "Rlogo.png" , package = "png") #' grid.pattern_image(x_hex, y_hex, filename = logo_filename, type = "fit") -#' +#' } +#' if (requireNamespace("magick")) { #' # "tile" `type` image pattern depends on `magick` functionality #' # which is not reliable across platforms #' grid::grid.newpage() diff --git a/R/pattern-both-gradient.R b/R/pattern-both-gradient.R index b481a05..f72b584 100644 --- a/R/pattern-both-gradient.R +++ b/R/pattern-both-gradient.R @@ -13,11 +13,13 @@ #' @param res Assumed resolution (in pixels per graphic device inch) to use when creating array pattern. #' @return A grid grob object invisibly. If `draw` is `TRUE` then also draws to the graphic device as a side effect. #' @examples -#' if (require("grid") && require("magick") && capabilities("png")) { +#' if (requireNamespace("magick") && capabilities("png")) { #' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) #' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) #' grid.pattern_gradient(x_hex, y_hex, fill = "green") -#' grid.newpage() +#' } +#' if (requireNamespace("magick") && capabilities("png")) { +#' grid::grid.newpage() #' grid.pattern_gradient(x_hex, y_hex, fill = "green", orientation = "radial") #' } #' @export diff --git a/R/pattern-both-rose.R b/R/pattern-both-rose.R index 8000ec6..cf9eda8 100644 --- a/R/pattern-both-rose.R +++ b/R/pattern-both-rose.R @@ -9,20 +9,22 @@ #' @return A grid grob object invisibly. If `draw` is `TRUE` then also draws to the graphic device as a side effect. #' @seealso See \url{https://en.wikipedia.org/wiki/Rose_(mathematics)} for more information. #' @examples -#' if (require("grid") && capabilities("png")) { +#' if (capabilities("png") || guess_has_R4.1_features("masks")) { #' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) #' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) -#' gp <- gpar(fill = c("blue", "red", "yellow", "green"), col = "black") -#' -#' grid.newpage() +#' gp <- grid::gpar(fill = c("blue", "red", "yellow", "green"), col = "black") #' grid.pattern_rose(x_hex, y_hex, #' spacing = 0.15, density = 0.5, angle = 0, #' frequency = 1:4, gp = gp) -#' grid.newpage() +#' } +#' if (capabilities("png") || guess_has_R4.1_features("masks")) { +#' grid::grid.newpage() #' grid.pattern_rose(x_hex, y_hex, #' spacing = 0.15, density = 0.5, angle = 0, #' frequency = 1/1:4, gp = gp) -#' grid.newpage() +#' } +#' if (capabilities("png") || guess_has_R4.1_features("masks")) { +#' grid::grid.newpage() #' grid.pattern_rose(x_hex, y_hex, #' spacing = 0.18, density = 0.5, angle = 0, #' frequency = c(3/2, 7/3, 5/4, 3/7), gp = gp) diff --git a/R/pattern-both-text.R b/R/pattern-both-text.R index 266bba9..7670bc2 100644 --- a/R/pattern-both-text.R +++ b/R/pattern-both-text.R @@ -11,14 +11,12 @@ #' @param fontface The font face. See [grid::gpar()] for more details. #' @return A grid grob object invisibly. If `draw` is `TRUE` then also draws to the graphic device as a side effect. #' @examples -#' if (require("grid") && -#' capabilities("png") && +#' if (capabilities("png") && #' gridpattern:::device_supports_unicode()) { #' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) #' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) #' #' playing_card_symbols <- c("\u2660", "\u2665", "\u2666", "\u2663") -#' grid.newpage() #' grid.pattern_text(x_hex, y_hex, #' shape = playing_card_symbols, #' colour = c("black", "red", "red", "black"), diff --git a/R/pattern-geometry-circle.R b/R/pattern-geometry-circle.R index 2297892..d03830b 100644 --- a/R/pattern-geometry-circle.R +++ b/R/pattern-geometry-circle.R @@ -28,21 +28,18 @@ #' more information about supported `subtype` arguments. #' @return A grid grob object invisibly. If `draw` is `TRUE` then also draws to the graphic device as a side effect. #' @examples -#' if (require("grid")) { -#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) -#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) -#' grid.pattern_circle(x_hex, y_hex, fill = c("blue", "yellow"), density = 0.5) -#' grid.newpage() -#' grid.pattern_circle(x_hex, y_hex, density = 0.8, grid = "hex_circle", -#' gp = gpar(fill = c("blue", "yellow", "red"))) -#' grid.newpage() -#' grid.pattern_circle(x_hex, y_hex, density = 1.2, grid = "hex_circle", -#' gp = gpar(fill = c("blue", "yellow", "red"))) -#' -#' # using a "twill_zigzag" 'weave' pattern -#' grid.newpage() -#' grid.pattern_circle(x_hex, y_hex, fill = "blue", density = 0.5, type = "twill_zigzag") -#' } +#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +#' grid.pattern_circle(x_hex, y_hex, fill = c("blue", "yellow"), density = 0.5) +#' grid::grid.newpage() +#' grid.pattern_circle(x_hex, y_hex, density = 0.8, grid = "hex_circle", +#' gp = gpar(fill = c("blue", "yellow", "red"))) +#' grid::grid.newpage() +#' grid.pattern_circle(x_hex, y_hex, density = 1.2, grid = "hex_circle", +#' gp = gpar(fill = c("blue", "yellow", "red"))) +#' # using a "twill_zigzag" 'weave' pattern +#' grid::grid.newpage() +#' grid.pattern_circle(x_hex, y_hex, fill = "blue", density = 0.5, type = "twill_zigzag") #' @seealso #' See [grid.pattern_regular_polygon()] for a more general case of this pattern. #' @export diff --git a/R/pattern-geometry-crosshatch.R b/R/pattern-geometry-crosshatch.R index 4cca813..b431deb 100644 --- a/R/pattern-geometry-crosshatch.R +++ b/R/pattern-geometry-crosshatch.R @@ -6,15 +6,13 @@ #' @param fill2 The fill colour for the \dQuote{top} crosshatch lines. #' @return A grid grob object invisibly. If `draw` is `TRUE` then also draws to the graphic device as a side effect. #' @examples -#' if (require("grid")) { -#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) -#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) -#' grid.pattern_crosshatch(x_hex, y_hex, colour = "black", fill = "blue", -#' fill2 = "yellow", density = 0.5) -#' grid.newpage() -#' grid.pattern_crosshatch(x_hex, y_hex, density = 0.3, -#' gp = gpar(col = "blue", fill = "yellow")) -#' } +#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +#' grid.pattern_crosshatch(x_hex, y_hex, colour = "black", fill = "blue", +#' fill2 = "yellow", density = 0.5) +#' grid::grid.newpage() +#' grid.pattern_crosshatch(x_hex, y_hex, density = 0.3, +#' gp = gpar(col = "blue", fill = "yellow")) #' @seealso [grid.pattern_weave()] which interweaves two sets of lines. #' For a single set of lines use [grid.pattern_stripe()]. #' @export diff --git a/R/pattern-geometry-pch.R b/R/pattern-geometry-pch.R index 2285fc2..200896f 100644 --- a/R/pattern-geometry-pch.R +++ b/R/pattern-geometry-pch.R @@ -10,36 +10,40 @@ #' @return A grid grob object invisibly. If `draw` is `TRUE` then also draws to the graphic device as a side effect. #' @seealso [grid.pattern_regular_polygon()] which is used to implement this pattern. #' @examples -#' if (require("grid")) { -#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) -#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) -#' gp <- gpar(col = "black", fill = "lightblue") +#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +#' gp <- grid::gpar(col = "black", fill = "lightblue") #' -#' # pch 0-6 are simple shapes with no fill -#' grid.pattern_pch(x_hex, y_hex, shape = 0:6, gp = gp, -#' spacing = 0.1, density = 0.4, angle = 0) -#' -#' # pch 7-14 are compound shapes with no fill -#' grid.newpage() -#' grid.pattern_pch(x_hex, y_hex, shape = 7:14, gp = gp, -#' spacing = 0.1, density = 0.4, angle = 0) -#' -#' # pch 15-20 are filled with 'col' -#' grid.newpage() -#' grid.pattern_pch(x_hex, y_hex, shape = 15:20, gp = gp, -#' spacing = 0.1, density = 0.4, angle = 0) -#' -#' # pch 21-25 are filled with 'fill' -#' grid.newpage() -#' grid.pattern_pch(x_hex, y_hex, shape = 21:25, gp = gp, -#' spacing = 0.1, density = 0.4, angle = 0) -#' -#' # using a 'basket' weave `type` with two shapes -#' grid.newpage() -#' grid.pattern_pch(x_hex, y_hex, shape = c(1,4), gp = gp, -#' type = "basket", -#' spacing = 0.1, density = 0.4, angle = 0) -#' } +#' if (capabilities("png") || guess_has_R4.1_features("masks")) { +#' # pch 0-6 are simple shapes with no fill +#' grid.pattern_pch(x_hex, y_hex, shape = 0:6, gp = gp, +#' spacing = 0.1, density = 0.4, angle = 0) +#' } +#' if (capabilities("png") || guess_has_R4.1_features("masks")) { +#' # pch 7-14 are compound shapes with no fill +#' grid::grid.newpage() +#' grid.pattern_pch(x_hex, y_hex, shape = 7:14, gp = gp, +#' spacing = 0.1, density = 0.4, angle = 0) +#' } +#' if (capabilities("png") || guess_has_R4.1_features("masks")) { +#' # pch 15-20 are filled with 'col' +#' grid::grid.newpage() +#' grid.pattern_pch(x_hex, y_hex, shape = 15:20, gp = gp, +#' spacing = 0.1, density = 0.4, angle = 0) +#' } +#' if (capabilities("png") || guess_has_R4.1_features("masks")) { +#' # pch 21-25 are filled with 'fill' +#' grid::grid.newpage() +#' grid.pattern_pch(x_hex, y_hex, shape = 21:25, gp = gp, +#' spacing = 0.1, density = 0.4, angle = 0) +#' } +#' if (capabilities("png") || guess_has_R4.1_features("masks")) { +#' # using a 'basket' weave `type` with two shapes +#' grid::grid.newpage() +#' grid.pattern_pch(x_hex, y_hex, shape = c(1,4), gp = gp, +#' type = "basket", +#' spacing = 0.1, density = 0.4, angle = 0) +#' } #' @export grid.pattern_pch <- function(x = c(0, 0, 1, 1), y = c(1, 0, 0, 1), id = 1L, ..., colour = gp$col %||% "grey20", diff --git a/R/pattern-geometry-regular_polygon.R b/R/pattern-geometry-regular_polygon.R index 139045b..e46d884 100644 --- a/R/pattern-geometry-regular_polygon.R +++ b/R/pattern-geometry-regular_polygon.R @@ -23,50 +23,46 @@ #' The tiling vignette features more examples of regular polygon tiling using #' this function `vignette("tiling", package = "gridpattern")`. #' @examples -#' if (require("grid")) { -#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) -#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) #' -#' # 'density', 'rot', and 'shape' are vectorized -#' grid.newpage() -#' grid.pattern_regular_polygon(x_hex, y_hex, colour = "black", -#' fill = c("blue", "yellow", "red"), -#' shape = c("convex4", "star8", "circle"), -#' density = c(0.45, 0.42, 0.4), -#' spacing = 0.08, angle = 0) +#' # 'density', 'rot', and 'shape' are vectorized +#' grid.pattern_regular_polygon(x_hex, y_hex, colour = "black", +#' fill = c("blue", "yellow", "red"), +#' shape = c("convex4", "star8", "circle"), +#' density = c(0.45, 0.42, 0.4), +#' spacing = 0.08, angle = 0) #' -#' # checker pattern using "square" shape -#' grid.newpage() -#' grid.pattern_regular_polygon(x_hex, y_hex, shape = "square", -#' colour = "transparent", -#' fill = c("black", "red", "blue", "yellow"), -#' angle = 0, density = 1.0, spacing = 0.2) +#' # checker pattern using "square" shape +#' grid::grid.newpage() +#' grid.pattern_regular_polygon(x_hex, y_hex, shape = "square", +#' colour = "transparent", +#' fill = c("black", "red", "blue", "yellow"), +#' angle = 0, density = 1.0, spacing = 0.2) #' -#' # checker pattern using the default "convex4" shape -#' grid.newpage() -#' grid.pattern_regular_polygon(x_hex, y_hex, density = 1.0, -#' colour = "black", fill = "blue") +#' # checker pattern using the default "convex4" shape +#' grid::grid.newpage() +#' grid.pattern_regular_polygon(x_hex, y_hex, density = 1.0, +#' colour = "black", fill = "blue") #' -#' # using a "twill_zigzag" 'weave' pattern -#' grid.newpage() -#' grid.pattern_regular_polygon(x_hex, y_hex, fill = c("blue", "yellow"), -#' shape = c("circle", "star8"), -#' density = c(0.5, 0.6), type = "twill_zigzag") +#' # using a "twill_zigzag" 'weave' pattern +#' grid::grid.newpage() +#' grid.pattern_regular_polygon(x_hex, y_hex, fill = c("blue", "yellow"), +#' shape = c("circle", "star8"), +#' density = c(0.5, 0.6), type = "twill_zigzag") #' -#' # hexagon tiling -#' grid.newpage() -#' grid.pattern_regular_polygon(x_hex, y_hex, color = "transparent", -#' fill = c("white", "grey", "black"), -#' density = 1.0, spacing = 0.1, -#' shape = "convex6", grid = "hex") +#' # hexagon tiling +#' grid::grid.newpage() +#' grid.pattern_regular_polygon(x_hex, y_hex, color = "transparent", +#' fill = c("white", "grey", "black"), +#' density = 1.0, spacing = 0.1, +#' shape = "convex6", grid = "hex") #' -#' # triangle tiling -#' grid.newpage() -#' grid.pattern_regular_polygon(x_hex, y_hex, fill = "green", -#' density = 1.0, spacing = 0.1, -#' shape = "convex3", grid = "hex") -#' -#' } +#' # triangle tiling +#' grid::grid.newpage() +#' grid.pattern_regular_polygon(x_hex, y_hex, fill = "green", +#' density = 1.0, spacing = 0.1, +#' shape = "convex3", grid = "hex") #' @export grid.pattern_regular_polygon <- function(x = c(0, 0, 1, 1), y = c(1, 0, 0, 1), id = 1L, ..., colour = gp$col %||% "grey20", diff --git a/R/pattern-geometry-stripe.R b/R/pattern-geometry-stripe.R index 024a9ba..055fb29 100644 --- a/R/pattern-geometry-stripe.R +++ b/R/pattern-geometry-stripe.R @@ -5,17 +5,15 @@ #' @inheritParams grid.pattern_circle #' @return A grid grob object invisibly. If `draw` is `TRUE` then also draws to the graphic device as a side effect. #' @examples -#' if (require("grid")) { -#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) -#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) -#' grid.pattern_stripe(x_hex, y_hex, colour = "black", -#' fill = c("red", "blue"), density = 0.4) +#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +#' grid.pattern_stripe(x_hex, y_hex, colour = "black", +#' fill = c("red", "blue"), density = 0.4) #' -#' # Can alternatively use "gpar()" to specify colour and line attributes -#' grid.newpage() -#' grid.pattern_stripe(x_hex, y_hex, density = 0.3, -#' gp = gpar(col = "blue", fill = "yellow")) -#' } +#' # Can alternatively use "gpar()" to specify colour and line attributes +#' grid::grid.newpage() +#' grid.pattern_stripe(x_hex, y_hex, density = 0.3, +#' gp = gpar(col = "blue", fill = "yellow")) #' @seealso `[grid.pattern_crosshatch()]` and `[grid.pattern_weave()]` for overlaying stripes. #' @export grid.pattern_stripe <- function(x = c(0, 0, 1, 1), y = c(1, 0, 0, 1), id = 1L, ..., diff --git a/R/pattern-geometry-tiling.R b/R/pattern-geometry-tiling.R index 1a57aab..204c750 100644 --- a/R/pattern-geometry-tiling.R +++ b/R/pattern-geometry-tiling.R @@ -56,33 +56,31 @@ #' information about these tilings as well as more #' examples of polygon tiling using the [grid.pattern_regular_polygon()] function. #' @examples -#' print(names_polygon_tiling) -#' if (require("grid")) { -#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) -#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) -#' gp1 <- gpar(fill = "yellow", col = "black") -#' gp2 <- gpar(fill = c("yellow", "red"), col = "black") -#' gp3 <- gpar(fill = c("yellow", "red", "blue"), col = "black") +#' print(names_polygon_tiling) #' -#' grid.pattern_polygon_tiling(x_hex, y_hex, type = "herringbone", gp = gp1) +#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +#' gp1 <- grid::gpar(fill = "yellow", col = "black") +#' gp2 <- grid::gpar(fill = c("yellow", "red"), col = "black") +#' gp3 <- grid::gpar(fill = c("yellow", "red", "blue"), col = "black") #' -#' grid.newpage() -#' grid.pattern_polygon_tiling(x_hex, y_hex, type = "hexagonal", -#' spacing = 0.2, gp = gp3) +#' grid.pattern_polygon_tiling(x_hex, y_hex, type = "herringbone", gp = gp1) #' -#' grid.newpage() -#' grid.pattern_polygon_tiling(x_hex, y_hex, type = "pythagorean", -#' spacing = 0.2, gp = gp2) +#' grid::grid.newpage() +#' grid.pattern_polygon_tiling(x_hex, y_hex, type = "hexagonal", +#' spacing = 0.2, gp = gp3) #' -#' grid.newpage() -#' grid.pattern_polygon_tiling(x_hex, y_hex, type = "snub_trihexagonal", -#' spacing = 0.2, gp = gp3) +#' grid::grid.newpage() +#' grid.pattern_polygon_tiling(x_hex, y_hex, type = "pythagorean", +#' spacing = 0.2, gp = gp2) #' -#' grid.newpage() -#' grid.pattern_polygon_tiling(x_hex, y_hex, type = "rhombille", -#' spacing = 0.2, gp = gp3) -#' } +#' grid::grid.newpage() +#' grid.pattern_polygon_tiling(x_hex, y_hex, type = "snub_trihexagonal", +#' spacing = 0.2, gp = gp3) #' +#' grid::grid.newpage() +#' grid.pattern_polygon_tiling(x_hex, y_hex, type = "rhombille", +#' spacing = 0.2, gp = gp3) #' @export grid.pattern_polygon_tiling <- function(x = c(0, 0, 1, 1), y = c(1, 0, 0, 1), id = 1L, ..., colour = gp$col %||% "grey20", diff --git a/R/pattern-geometry-wave.R b/R/pattern-geometry-wave.R index dd1f45a..621a667 100644 --- a/R/pattern-geometry-wave.R +++ b/R/pattern-geometry-wave.R @@ -8,22 +8,19 @@ #' @param type Either \dQuote{sine} or \dQuote{triangle} (default). #' @return A grid grob object invisibly. If `draw` is `TRUE` then also draws to the graphic device as a side effect. #' @examples -#' if (require("grid")) { -#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) -#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) -#' grid.newpage() -#' grid.pattern_wave(x_hex, y_hex, colour = "black", type = "sine", -#' fill = c("red", "blue"), density = 0.4, -#' spacing = 0.15, angle = 0, -#' amplitude = 0.05, frequency = 1 / 0.20) +#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +#' grid::grid.newpage() +#' grid.pattern_wave(x_hex, y_hex, colour = "black", type = "sine", +#' fill = c("red", "blue"), density = 0.4, +#' spacing = 0.15, angle = 0, +#' amplitude = 0.05, frequency = 1 / 0.20) #' -#' # zig-zag pattern is a wave of `type` "triangle" -#' grid.newpage() -#' grid.pattern_wave(x_hex, y_hex, colour = "black", type = "triangle", -#' fill = c("red", "blue"), density = 0.4, -#' spacing = 0.15, angle = 0, amplitude = 0.075) -#' -#' } +#' # zig-zag pattern is a wave of `type` "triangle" +#' grid::grid.newpage() +#' grid.pattern_wave(x_hex, y_hex, colour = "black", type = "triangle", +#' fill = c("red", "blue"), density = 0.4, +#' spacing = 0.15, angle = 0, amplitude = 0.075) #' @seealso Use [grid.pattern_stripe()] for straight lines instead of waves. #' @export grid.pattern_wave <- function(x = c(0, 0, 1, 1), y = c(1, 0, 0, 1), id = 1L, ..., diff --git a/R/pattern-geometry-weave.R b/R/pattern-geometry-weave.R index d1c4eca..2089f34 100644 --- a/R/pattern-geometry-weave.R +++ b/R/pattern-geometry-weave.R @@ -9,37 +9,34 @@ #' @param subtype The weave subtype. See [pattern_weave()] for more details. #' @return A grid grob object invisibly. If `draw` is `TRUE` then also draws to the graphic device as a side effect. #' @examples -#' if (require("grid")) { -#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) -#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) -#' gp <- gpar(colour = "black", fill = "lightblue", lwd=0.5) +#' x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +#' y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +#' gp <- grid::gpar(colour = "black", fill = "lightblue", lwd=0.5) #' -#' # Plain weave (default weave) -#' grid.pattern_weave(x_hex, y_hex, fill2 = "yellow", -#' gp = gp, spacing = 0.1, density = 0.3) +#' # Plain weave (default weave) +#' grid.pattern_weave(x_hex, y_hex, fill2 = "yellow", +#' gp = gp, spacing = 0.1, density = 0.3) #' -#' # Irregular matt weave -#' grid.newpage() -#' grid.pattern_weave(x_hex, y_hex, type = "matt_irregular", -#' fill2 = "yellow", gp = gp, spacing = 0.1, density = 0.3) +#' # Irregular matt weave +#' grid::grid.newpage() +#' grid.pattern_weave(x_hex, y_hex, type = "matt_irregular", +#' fill2 = "yellow", gp = gp, spacing = 0.1, density = 0.3) #' -#' # Twill weave -#' grid.newpage() -#' grid.pattern_weave(x_hex, y_hex, type = "twill", -#' fill2 = "yellow", gp = gp, spacing = 0.1, density = 0.3) +#' # Twill weave +#' grid::grid.newpage() +#' grid.pattern_weave(x_hex, y_hex, type = "twill", +#' fill2 = "yellow", gp = gp, spacing = 0.1, density = 0.3) #' -#' # Zig-zag twill -#' grid.newpage() -#' grid.pattern_weave(x_hex, y_hex, type = "twill_zigzag", -#' fill2 = "yellow", gp = gp, spacing = 0.05, density = 0.7) +#' # Zig-zag twill +#' grid::grid.newpage() +#' grid.pattern_weave(x_hex, y_hex, type = "twill_zigzag", +#' fill2 = "yellow", gp = gp, spacing = 0.05, density = 0.7) #' -#' # Herringbone twill with density 1 -#' grid.newpage() -#' gp$col <- NA -#' grid.pattern_weave(x_hex, y_hex, type = "twill_herringbone", -#' fill2 = "yellow", gp = gp, spacing = 0.05, density = 1.0) -#' -#' } +#' # Herringbone twill with density 1 +#' grid::grid.newpage() +#' gp$col <- NA +#' grid.pattern_weave(x_hex, y_hex, type = "twill_herringbone", +#' fill2 = "yellow", gp = gp, spacing = 0.05, density = 1.0) #' @seealso [pattern_weave()] #' @export grid.pattern_weave <- function(x = c(0, 0, 1, 1), y = c(1, 0, 0, 1), id = 1L, ..., diff --git a/R/star_scale.R b/R/star_scale.R index b31503f..2ad8efb 100644 --- a/R/star_scale.R +++ b/R/star_scale.R @@ -25,11 +25,8 @@ #' star_angle(8, scale) #' star_angle(8, scale, external = TRUE) #' -#' if (require("grid")) { -#' grid.pattern_regular_polygon(shape = "star8", scale = scale, angle = 0, -#' spacing = 0.2, density = 0.8) -#' } -#' +#' grid.pattern_regular_polygon(shape = "star8", scale = scale, angle = 0, +#' spacing = 0.2, density = 0.8) #' @export star_scale <- function(n_vertices, angle, external = FALSE) { if (external) diff --git a/man/alphaMaskGrob.Rd b/man/alphaMaskGrob.Rd index a1bb426..3fd6133 100644 --- a/man/alphaMaskGrob.Rd +++ b/man/alphaMaskGrob.Rd @@ -65,9 +65,9 @@ A \code{grid} grob id = rep(1:2, each = 7), rule = "evenodd", gp = gp) masked <- alphaMaskGrob(maskee, masker, use_R4.1_masks = FALSE) - grid.newpage() grid.draw(masked) - + } + if (capabilities("png") && require("grid")) { maskee_transparent <- rectGrob(gp = gpar(col = NA, fill = "blue")) gp <- gpar(lwd = 20, col = "black", fill = grDevices::rgb(0, 0, 0, 0.5)) masker_transparent <- editGrob(masker, gp = gp) diff --git a/man/grid.pattern.Rd b/man/grid.pattern.Rd index eb460f5..0d7a70c 100644 --- a/man/grid.pattern.Rd +++ b/man/grid.pattern.Rd @@ -127,51 +127,51 @@ See \code{\link[=grid.pattern_weave]{grid.pattern_weave()}} for more information \examples{ print(names_pattern) \donttest{ # Once took more >10s on a CRAN autocheck - if (require("grid")) { - x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - - # geometry-based patterns - # 'stripe' pattern - grid.newpage() - grid.pattern("stripe", x_hex, y_hex, - colour="black", fill=c("yellow", "blue"), density = 0.5) - - # Can alternatively use "gpar()" to specify colour and line attributes - grid.newpage() - grid.pattern("stripe", x_hex, y_hex, gp = gpar(col="blue", fill="red", lwd=2)) - - # 'weave' pattern - grid.newpage() - grid.pattern("weave", x_hex, y_hex, type = "satin", - colour = "black", fill = "lightblue", fill2 = "yellow", - density = 0.3) - - # 'regular_polygon' pattern - grid.newpage() - grid.pattern_regular_polygon(x_hex, y_hex, colour = "black", - fill = c("blue", "yellow", "red"), - shape = c("convex4", "star8", "circle"), - density = c(0.45, 0.42, 0.4), - spacing = 0.08, angle = 0) - - # can be used to achieve a variety of 'tiling' effects - grid.newpage() - grid.pattern_regular_polygon(x_hex, y_hex, color = "transparent", - fill = c("white", "grey", "black"), - density = 1.0, spacing = 0.1, - shape = "convex6", grid = "hex") - if (require("magick")) { - # array-based patterns - # 'image' pattern - logo_filename <- system.file("img", "Rlogo.png" , package="png") - grid.newpage() - grid.pattern("image", x_hex, y_hex, filename=logo_filename, type="fit") - - # 'plasma' pattern - grid.newpage() - grid.pattern("plasma", x_hex, y_hex, fill="green") - } + x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) + y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) + + # geometry-based patterns + # 'stripe' pattern + grid::grid.newpage() + grid.pattern("stripe", x_hex, y_hex, + colour="black", fill=c("yellow", "blue"), density = 0.5) + + # Can alternatively use "gpar()" to specify colour and line attributes + grid::grid.newpage() + grid.pattern("stripe", x_hex, y_hex, + gp = grid::gpar(col="blue", fill="red", lwd=2)) + + # 'weave' pattern + grid::grid.newpage() + grid.pattern("weave", x_hex, y_hex, type = "satin", + colour = "black", fill = "lightblue", fill2 = "yellow", + density = 0.3) + + # 'regular_polygon' pattern + grid::grid.newpage() + grid.pattern_regular_polygon(x_hex, y_hex, colour = "black", + fill = c("blue", "yellow", "red"), + shape = c("convex4", "star8", "circle"), + density = c(0.45, 0.42, 0.4), + spacing = 0.08, angle = 0) + + # can be used to achieve a variety of 'tiling' effects + grid::grid.newpage() + grid.pattern_regular_polygon(x_hex, y_hex, color = "transparent", + fill = c("white", "grey", "black"), + density = 1.0, spacing = 0.1, + shape = "convex6", grid = "hex") + if (suppressPackageStartupMessages(requireNamespace("magick", quietly = TRUE))) { + # array-based patterns + # 'image' pattern + logo_filename <- system.file("img", "Rlogo.png" , package="png") + grid::grid.newpage() + grid.pattern("image", x_hex, y_hex, filename=logo_filename, type="fit") + } + if (suppressPackageStartupMessages(requireNamespace("magick", quietly = TRUE))) { + # 'plasma' pattern + grid::grid.newpage() + grid.pattern("plasma", x_hex, y_hex, fill="green") } } } diff --git a/man/grid.pattern_ambient.Rd b/man/grid.pattern_ambient.Rd index 8888088..98b03b8 100644 --- a/man/grid.pattern_ambient.Rd +++ b/man/grid.pattern_ambient.Rd @@ -118,10 +118,12 @@ A grid grob object invisibly. If \code{draw} is \code{TRUE} then also draws to \code{grid.pattern_ambient()} draws noise patterns onto the graphic device powered by the \code{ambient} package. } \examples{ - if (requireNamespace("ambient")) { + if (requireNamespace("ambient", quietly = TRUE)) { x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) grid.pattern_ambient(x_hex, y_hex, fill = "green", fill2 = "blue") + } + if (requireNamespace("ambient")) { grid::grid.newpage() grid.pattern_ambient(x_hex, y_hex, fill = "green", fill2 = "blue", type = "cubic") } diff --git a/man/grid.pattern_circle.Rd b/man/grid.pattern_circle.Rd index 1fc5cc4..90e82d9 100644 --- a/man/grid.pattern_circle.Rd +++ b/man/grid.pattern_circle.Rd @@ -97,21 +97,18 @@ A grid grob object invisibly. If \code{draw} is \code{TRUE} then also draws to \code{grid.pattern_circle()} draws a circle pattern onto the graphic device. } \examples{ - if (require("grid")) { - x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - grid.pattern_circle(x_hex, y_hex, fill = c("blue", "yellow"), density = 0.5) - grid.newpage() - grid.pattern_circle(x_hex, y_hex, density = 0.8, grid = "hex_circle", - gp = gpar(fill = c("blue", "yellow", "red"))) - grid.newpage() - grid.pattern_circle(x_hex, y_hex, density = 1.2, grid = "hex_circle", - gp = gpar(fill = c("blue", "yellow", "red"))) - - # using a "twill_zigzag" 'weave' pattern - grid.newpage() - grid.pattern_circle(x_hex, y_hex, fill = "blue", density = 0.5, type = "twill_zigzag") - } +x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +grid.pattern_circle(x_hex, y_hex, fill = c("blue", "yellow"), density = 0.5) +grid::grid.newpage() +grid.pattern_circle(x_hex, y_hex, density = 0.8, grid = "hex_circle", + gp = gpar(fill = c("blue", "yellow", "red"))) +grid::grid.newpage() +grid.pattern_circle(x_hex, y_hex, density = 1.2, grid = "hex_circle", + gp = gpar(fill = c("blue", "yellow", "red"))) +# using a "twill_zigzag" 'weave' pattern +grid::grid.newpage() +grid.pattern_circle(x_hex, y_hex, fill = "blue", density = 0.5, type = "twill_zigzag") } \seealso{ See \code{\link[=grid.pattern_regular_polygon]{grid.pattern_regular_polygon()}} for a more general case of this pattern. diff --git a/man/grid.pattern_crosshatch.Rd b/man/grid.pattern_crosshatch.Rd index bb4c8d7..6626d80 100644 --- a/man/grid.pattern_crosshatch.Rd +++ b/man/grid.pattern_crosshatch.Rd @@ -90,15 +90,13 @@ A grid grob object invisibly. If \code{draw} is \code{TRUE} then also draws to \code{grid.pattern_crosshatch()} draws a crosshatch pattern onto the graphic device. } \examples{ - if (require("grid")) { - x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - grid.pattern_crosshatch(x_hex, y_hex, colour = "black", fill = "blue", - fill2 = "yellow", density = 0.5) - grid.newpage() - grid.pattern_crosshatch(x_hex, y_hex, density = 0.3, - gp = gpar(col = "blue", fill = "yellow")) - } +x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +grid.pattern_crosshatch(x_hex, y_hex, colour = "black", fill = "blue", + fill2 = "yellow", density = 0.5) +grid::grid.newpage() +grid.pattern_crosshatch(x_hex, y_hex, density = 0.3, + gp = gpar(col = "blue", fill = "yellow")) } \seealso{ \code{\link[=grid.pattern_weave]{grid.pattern_weave()}} which interweaves two sets of lines. diff --git a/man/grid.pattern_gradient.Rd b/man/grid.pattern_gradient.Rd index d928225..852375b 100644 --- a/man/grid.pattern_gradient.Rd +++ b/man/grid.pattern_gradient.Rd @@ -74,11 +74,13 @@ A grid grob object invisibly. If \code{draw} is \code{TRUE} then also draws to \code{grid.pattern_gradient()} draws a gradient pattern onto the graphic device. } \examples{ - if (require("grid") && require("magick") && capabilities("png")) { + if (requireNamespace("magick") && capabilities("png")) { x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) grid.pattern_gradient(x_hex, y_hex, fill = "green") - grid.newpage() + } + if (requireNamespace("magick") && capabilities("png")) { + grid::grid.newpage() grid.pattern_gradient(x_hex, y_hex, fill = "green", orientation = "radial") } } diff --git a/man/grid.pattern_image.Rd b/man/grid.pattern_image.Rd index ab460b9..14f35ba 100644 --- a/man/grid.pattern_image.Rd +++ b/man/grid.pattern_image.Rd @@ -93,7 +93,8 @@ Affected by \code{scale} and \code{gravity}.} y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) logo_filename <- system.file("img", "Rlogo.png" , package = "png") grid.pattern_image(x_hex, y_hex, filename = logo_filename, type = "fit") - + } + if (requireNamespace("magick")) { # "tile" `type` image pattern depends on `magick` functionality # which is not reliable across platforms grid::grid.newpage() diff --git a/man/grid.pattern_pch.Rd b/man/grid.pattern_pch.Rd index b9df337..adddeef 100644 --- a/man/grid.pattern_pch.Rd +++ b/man/grid.pattern_pch.Rd @@ -110,36 +110,40 @@ A grid grob object invisibly. If \code{draw} is \code{TRUE} then also draws to \code{grid.pattern_pch()} draws a plotting character pattern onto the graphic device. } \examples{ - if (require("grid")) { - x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - gp <- gpar(col = "black", fill = "lightblue") - - # pch 0-6 are simple shapes with no fill - grid.pattern_pch(x_hex, y_hex, shape = 0:6, gp = gp, - spacing = 0.1, density = 0.4, angle = 0) - - # pch 7-14 are compound shapes with no fill - grid.newpage() - grid.pattern_pch(x_hex, y_hex, shape = 7:14, gp = gp, - spacing = 0.1, density = 0.4, angle = 0) - - # pch 15-20 are filled with 'col' - grid.newpage() - grid.pattern_pch(x_hex, y_hex, shape = 15:20, gp = gp, - spacing = 0.1, density = 0.4, angle = 0) - - # pch 21-25 are filled with 'fill' - grid.newpage() - grid.pattern_pch(x_hex, y_hex, shape = 21:25, gp = gp, - spacing = 0.1, density = 0.4, angle = 0) - - # using a 'basket' weave `type` with two shapes - grid.newpage() - grid.pattern_pch(x_hex, y_hex, shape = c(1,4), gp = gp, - type = "basket", - spacing = 0.1, density = 0.4, angle = 0) - } +x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +gp <- grid::gpar(col = "black", fill = "lightblue") + +if (capabilities("png") || guess_has_R4.1_features("masks")) { + # pch 0-6 are simple shapes with no fill + grid.pattern_pch(x_hex, y_hex, shape = 0:6, gp = gp, + spacing = 0.1, density = 0.4, angle = 0) +} +if (capabilities("png") || guess_has_R4.1_features("masks")) { + # pch 7-14 are compound shapes with no fill + grid::grid.newpage() + grid.pattern_pch(x_hex, y_hex, shape = 7:14, gp = gp, + spacing = 0.1, density = 0.4, angle = 0) +} +if (capabilities("png") || guess_has_R4.1_features("masks")) { + # pch 15-20 are filled with 'col' + grid::grid.newpage() + grid.pattern_pch(x_hex, y_hex, shape = 15:20, gp = gp, + spacing = 0.1, density = 0.4, angle = 0) +} +if (capabilities("png") || guess_has_R4.1_features("masks")) { + # pch 21-25 are filled with 'fill' + grid::grid.newpage() + grid.pattern_pch(x_hex, y_hex, shape = 21:25, gp = gp, + spacing = 0.1, density = 0.4, angle = 0) +} +if (capabilities("png") || guess_has_R4.1_features("masks")) { + # using a 'basket' weave `type` with two shapes + grid::grid.newpage() + grid.pattern_pch(x_hex, y_hex, shape = c(1,4), gp = gp, + type = "basket", + spacing = 0.1, density = 0.4, angle = 0) +} } \seealso{ \code{\link[=grid.pattern_regular_polygon]{grid.pattern_regular_polygon()}} which is used to implement this pattern. diff --git a/man/grid.pattern_polygon_tiling.Rd b/man/grid.pattern_polygon_tiling.Rd index c4eaa02..766ebd7 100644 --- a/man/grid.pattern_polygon_tiling.Rd +++ b/man/grid.pattern_polygon_tiling.Rd @@ -134,33 +134,31 @@ dodecagons, hexagons, and squares.} } } \examples{ - print(names_polygon_tiling) - if (require("grid")) { - x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - gp1 <- gpar(fill = "yellow", col = "black") - gp2 <- gpar(fill = c("yellow", "red"), col = "black") - gp3 <- gpar(fill = c("yellow", "red", "blue"), col = "black") +print(names_polygon_tiling) - grid.pattern_polygon_tiling(x_hex, y_hex, type = "herringbone", gp = gp1) +x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +gp1 <- grid::gpar(fill = "yellow", col = "black") +gp2 <- grid::gpar(fill = c("yellow", "red"), col = "black") +gp3 <- grid::gpar(fill = c("yellow", "red", "blue"), col = "black") - grid.newpage() - grid.pattern_polygon_tiling(x_hex, y_hex, type = "hexagonal", - spacing = 0.2, gp = gp3) +grid.pattern_polygon_tiling(x_hex, y_hex, type = "herringbone", gp = gp1) - grid.newpage() - grid.pattern_polygon_tiling(x_hex, y_hex, type = "pythagorean", - spacing = 0.2, gp = gp2) +grid::grid.newpage() +grid.pattern_polygon_tiling(x_hex, y_hex, type = "hexagonal", + spacing = 0.2, gp = gp3) - grid.newpage() - grid.pattern_polygon_tiling(x_hex, y_hex, type = "snub_trihexagonal", - spacing = 0.2, gp = gp3) +grid::grid.newpage() +grid.pattern_polygon_tiling(x_hex, y_hex, type = "pythagorean", + spacing = 0.2, gp = gp2) - grid.newpage() - grid.pattern_polygon_tiling(x_hex, y_hex, type = "rhombille", - spacing = 0.2, gp = gp3) - } +grid::grid.newpage() +grid.pattern_polygon_tiling(x_hex, y_hex, type = "snub_trihexagonal", + spacing = 0.2, gp = gp3) +grid::grid.newpage() +grid.pattern_polygon_tiling(x_hex, y_hex, type = "rhombille", + spacing = 0.2, gp = gp3) } \seealso{ The tiling vignette \code{vignette("tiling", package = "gridpattern")} for more diff --git a/man/grid.pattern_regular_polygon.Rd b/man/grid.pattern_regular_polygon.Rd index 9b1855b..ccb838c 100644 --- a/man/grid.pattern_regular_polygon.Rd +++ b/man/grid.pattern_regular_polygon.Rd @@ -118,50 +118,46 @@ A grid grob object invisibly. If \code{draw} is \code{TRUE} then also draws to \code{grid.pattern_regular_polygon()} draws a regular polygon pattern onto the graphic device. } \examples{ - if (require("grid")) { - x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - - # 'density', 'rot', and 'shape' are vectorized - grid.newpage() - grid.pattern_regular_polygon(x_hex, y_hex, colour = "black", - fill = c("blue", "yellow", "red"), - shape = c("convex4", "star8", "circle"), - density = c(0.45, 0.42, 0.4), - spacing = 0.08, angle = 0) - - # checker pattern using "square" shape - grid.newpage() - grid.pattern_regular_polygon(x_hex, y_hex, shape = "square", - colour = "transparent", - fill = c("black", "red", "blue", "yellow"), - angle = 0, density = 1.0, spacing = 0.2) - - # checker pattern using the default "convex4" shape - grid.newpage() - grid.pattern_regular_polygon(x_hex, y_hex, density = 1.0, - colour = "black", fill = "blue") - - # using a "twill_zigzag" 'weave' pattern - grid.newpage() - grid.pattern_regular_polygon(x_hex, y_hex, fill = c("blue", "yellow"), - shape = c("circle", "star8"), - density = c(0.5, 0.6), type = "twill_zigzag") - - # hexagon tiling - grid.newpage() - grid.pattern_regular_polygon(x_hex, y_hex, color = "transparent", - fill = c("white", "grey", "black"), - density = 1.0, spacing = 0.1, - shape = "convex6", grid = "hex") - - # triangle tiling - grid.newpage() - grid.pattern_regular_polygon(x_hex, y_hex, fill = "green", - density = 1.0, spacing = 0.1, - shape = "convex3", grid = "hex") - - } +x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) + +# 'density', 'rot', and 'shape' are vectorized +grid.pattern_regular_polygon(x_hex, y_hex, colour = "black", + fill = c("blue", "yellow", "red"), + shape = c("convex4", "star8", "circle"), + density = c(0.45, 0.42, 0.4), + spacing = 0.08, angle = 0) + +# checker pattern using "square" shape +grid::grid.newpage() +grid.pattern_regular_polygon(x_hex, y_hex, shape = "square", + colour = "transparent", + fill = c("black", "red", "blue", "yellow"), + angle = 0, density = 1.0, spacing = 0.2) + +# checker pattern using the default "convex4" shape +grid::grid.newpage() +grid.pattern_regular_polygon(x_hex, y_hex, density = 1.0, + colour = "black", fill = "blue") + +# using a "twill_zigzag" 'weave' pattern +grid::grid.newpage() +grid.pattern_regular_polygon(x_hex, y_hex, fill = c("blue", "yellow"), + shape = c("circle", "star8"), + density = c(0.5, 0.6), type = "twill_zigzag") + +# hexagon tiling +grid::grid.newpage() +grid.pattern_regular_polygon(x_hex, y_hex, color = "transparent", + fill = c("white", "grey", "black"), + density = 1.0, spacing = 0.1, + shape = "convex6", grid = "hex") + +# triangle tiling +grid::grid.newpage() +grid.pattern_regular_polygon(x_hex, y_hex, fill = "green", + density = 1.0, spacing = 0.1, + shape = "convex3", grid = "hex") } \seealso{ \code{\link[=grid.pattern_circle]{grid.pattern_circle()}} for a special case of this pattern. diff --git a/man/grid.pattern_rose.Rd b/man/grid.pattern_rose.Rd index 5bc664f..07a052f 100644 --- a/man/grid.pattern_rose.Rd +++ b/man/grid.pattern_rose.Rd @@ -121,20 +121,22 @@ A grid grob object invisibly. If \code{draw} is \code{TRUE} then also draws to \code{grid.pattern_rose()} draws a rose curve pattern onto the graphic device. } \examples{ - if (require("grid") && capabilities("png")) { + if (capabilities("png") || guess_has_R4.1_features("masks")) { x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - gp <- gpar(fill = c("blue", "red", "yellow", "green"), col = "black") - - grid.newpage() + gp <- grid::gpar(fill = c("blue", "red", "yellow", "green"), col = "black") grid.pattern_rose(x_hex, y_hex, spacing = 0.15, density = 0.5, angle = 0, frequency = 1:4, gp = gp) - grid.newpage() + } + if (capabilities("png") || guess_has_R4.1_features("masks")) { + grid::grid.newpage() grid.pattern_rose(x_hex, y_hex, spacing = 0.15, density = 0.5, angle = 0, frequency = 1/1:4, gp = gp) - grid.newpage() + } + if (capabilities("png") || guess_has_R4.1_features("masks")) { + grid::grid.newpage() grid.pattern_rose(x_hex, y_hex, spacing = 0.18, density = 0.5, angle = 0, frequency = c(3/2, 7/3, 5/4, 3/7), gp = gp) diff --git a/man/grid.pattern_stripe.Rd b/man/grid.pattern_stripe.Rd index 912222d..54353a4 100644 --- a/man/grid.pattern_stripe.Rd +++ b/man/grid.pattern_stripe.Rd @@ -87,17 +87,15 @@ A grid grob object invisibly. If \code{draw} is \code{TRUE} then also draws to \code{grid.pattern_stripe()} draws a stripe pattern onto the graphic device. } \examples{ - if (require("grid")) { - x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - grid.pattern_stripe(x_hex, y_hex, colour = "black", - fill = c("red", "blue"), density = 0.4) - - # Can alternatively use "gpar()" to specify colour and line attributes - grid.newpage() - grid.pattern_stripe(x_hex, y_hex, density = 0.3, - gp = gpar(col = "blue", fill = "yellow")) - } +x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +grid.pattern_stripe(x_hex, y_hex, colour = "black", + fill = c("red", "blue"), density = 0.4) + +# Can alternatively use "gpar()" to specify colour and line attributes +grid::grid.newpage() +grid.pattern_stripe(x_hex, y_hex, density = 0.3, + gp = gpar(col = "blue", fill = "yellow")) } \seealso{ \verb{[grid.pattern_crosshatch()]} and \verb{[grid.pattern_weave()]} for overlaying stripes. diff --git a/man/grid.pattern_text.Rd b/man/grid.pattern_text.Rd index d2de5d7..0a30656 100644 --- a/man/grid.pattern_text.Rd +++ b/man/grid.pattern_text.Rd @@ -120,14 +120,12 @@ A grid grob object invisibly. If \code{draw} is \code{TRUE} then also draws to \code{grid.pattern_text()} draws a text character pattern onto the graphic device. } \examples{ -if (require("grid") && - capabilities("png") && +if (capabilities("png") && gridpattern:::device_supports_unicode()) { x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) playing_card_symbols <- c("\u2660", "\u2665", "\u2666", "\u2663") - grid.newpage() grid.pattern_text(x_hex, y_hex, shape = playing_card_symbols, colour = c("black", "red", "red", "black"), diff --git a/man/grid.pattern_wave.Rd b/man/grid.pattern_wave.Rd index 8060723..870587a 100644 --- a/man/grid.pattern_wave.Rd +++ b/man/grid.pattern_wave.Rd @@ -96,22 +96,19 @@ A grid grob object invisibly. If \code{draw} is \code{TRUE} then also draws to \code{grid.pattern_wave()} draws a wave pattern onto the graphic device. } \examples{ - if (require("grid")) { - x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - grid.newpage() - grid.pattern_wave(x_hex, y_hex, colour = "black", type = "sine", - fill = c("red", "blue"), density = 0.4, - spacing = 0.15, angle = 0, - amplitude = 0.05, frequency = 1 / 0.20) - - # zig-zag pattern is a wave of `type` "triangle" - grid.newpage() - grid.pattern_wave(x_hex, y_hex, colour = "black", type = "triangle", - fill = c("red", "blue"), density = 0.4, - spacing = 0.15, angle = 0, amplitude = 0.075) - - } +x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +grid::grid.newpage() +grid.pattern_wave(x_hex, y_hex, colour = "black", type = "sine", + fill = c("red", "blue"), density = 0.4, + spacing = 0.15, angle = 0, + amplitude = 0.05, frequency = 1 / 0.20) + +# zig-zag pattern is a wave of `type` "triangle" +grid::grid.newpage() +grid.pattern_wave(x_hex, y_hex, colour = "black", type = "triangle", + fill = c("red", "blue"), density = 0.4, + spacing = 0.15, angle = 0, amplitude = 0.075) } \seealso{ Use \code{\link[=grid.pattern_stripe]{grid.pattern_stripe()}} for straight lines instead of waves. diff --git a/man/grid.pattern_weave.Rd b/man/grid.pattern_weave.Rd index 866f5e8..e57e76b 100644 --- a/man/grid.pattern_weave.Rd +++ b/man/grid.pattern_weave.Rd @@ -96,37 +96,34 @@ A grid grob object invisibly. If \code{draw} is \code{TRUE} then also draws to \code{grid.pattern_weave()} draws a weave pattern onto the graphic device. } \examples{ - if (require("grid")) { - x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) - gp <- gpar(colour = "black", fill = "lightblue", lwd=0.5) - - # Plain weave (default weave) - grid.pattern_weave(x_hex, y_hex, fill2 = "yellow", - gp = gp, spacing = 0.1, density = 0.3) - - # Irregular matt weave - grid.newpage() - grid.pattern_weave(x_hex, y_hex, type = "matt_irregular", - fill2 = "yellow", gp = gp, spacing = 0.1, density = 0.3) - - # Twill weave - grid.newpage() - grid.pattern_weave(x_hex, y_hex, type = "twill", - fill2 = "yellow", gp = gp, spacing = 0.1, density = 0.3) - - # Zig-zag twill - grid.newpage() - grid.pattern_weave(x_hex, y_hex, type = "twill_zigzag", - fill2 = "yellow", gp = gp, spacing = 0.05, density = 0.7) - - # Herringbone twill with density 1 - grid.newpage() - gp$col <- NA - grid.pattern_weave(x_hex, y_hex, type = "twill_herringbone", - fill2 = "yellow", gp = gp, spacing = 0.05, density = 1.0) - - } +x_hex <- 0.5 + 0.5 * cos(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +y_hex <- 0.5 + 0.5 * sin(seq(2 * pi / 4, by = 2 * pi / 6, length.out = 6)) +gp <- grid::gpar(colour = "black", fill = "lightblue", lwd=0.5) + +# Plain weave (default weave) +grid.pattern_weave(x_hex, y_hex, fill2 = "yellow", + gp = gp, spacing = 0.1, density = 0.3) + +# Irregular matt weave +grid::grid.newpage() +grid.pattern_weave(x_hex, y_hex, type = "matt_irregular", + fill2 = "yellow", gp = gp, spacing = 0.1, density = 0.3) + +# Twill weave +grid::grid.newpage() +grid.pattern_weave(x_hex, y_hex, type = "twill", + fill2 = "yellow", gp = gp, spacing = 0.1, density = 0.3) + +# Zig-zag twill +grid::grid.newpage() +grid.pattern_weave(x_hex, y_hex, type = "twill_zigzag", + fill2 = "yellow", gp = gp, spacing = 0.05, density = 0.7) + +# Herringbone twill with density 1 +grid::grid.newpage() +gp$col <- NA +grid.pattern_weave(x_hex, y_hex, type = "twill_herringbone", + fill2 = "yellow", gp = gp, spacing = 0.05, density = 1.0) } \seealso{ \code{\link[=pattern_weave]{pattern_weave()}} diff --git a/man/star_scale.Rd b/man/star_scale.Rd index d2220d9..25dbb6d 100644 --- a/man/star_scale.Rd +++ b/man/star_scale.Rd @@ -44,9 +44,6 @@ and either the internal or external angle of the regular star polygon. star_angle(8, scale) star_angle(8, scale, external = TRUE) - if (require("grid")) { - grid.pattern_regular_polygon(shape = "star8", scale = scale, angle = 0, - spacing = 0.2, density = 0.8) - } - + grid.pattern_regular_polygon(shape = "star8", scale = scale, angle = 0, + spacing = 0.2, density = 0.8) }