From a175222ddb208e4a559e4bb355b65b29bcb5ea2e Mon Sep 17 00:00:00 2001 From: Trevor L Davis Date: Wed, 12 Jan 2022 08:07:33 -0800 Subject: [PATCH] docs: Update README * Change {ggpattern} hex example to use multiple polygon tilings. * Fix (third) {ggpattern} developing patterns link. --- README.Rmd | 24 +++++++++++------------- README.md | 24 +++++++++++------------- 2 files changed, 22 insertions(+), 26 deletions(-) diff --git a/README.Rmd b/README.Rmd index b75efe1..73133a1 100644 --- a/README.Rmd +++ b/README.Rmd @@ -137,7 +137,7 @@ grid.pattern_weave(x_hex, y_hex, type = "satin", ## Using these patterns with the "ggpattern" package -The patterns provided by ``gridpattern`` can be used to create [custom ggpattern geometry-based patterns](https://coolbutuseless.github.io/package/ggpattern/articles/developing-patterns-2.html). +The patterns provided by ``gridpattern`` can be used to create [custom ggpattern geometry-based patterns](https://coolbutuseless.github.io/package/ggpattern/articles/developing-patterns.html). Here is an example of creating a new "multicolor_stripe" pattern that supports comma-separated ``pattern_fill`` and/or ``pattern_colour`` aesthetics: @@ -171,26 +171,21 @@ ggplot(df, aes(trt, outcome)) + pattern_fill = "grey30,grey70,white,grey70") ``` -And here is an example of creating a "hex_tile" pattern that creates -a three-color hexagonal tiling using the ``fill`` colour, the ``pattern_fill`` colour, +And here is an example of creating a "tiling3" pattern that creates +three-color polygon tilings using the ``fill`` colour, the ``pattern_fill`` colour, and their "average" color. ```{r hex_ggpattern} -hex_pattern <- function(params, boundary_df, aspect_ratio, legend = FALSE) { +tiling3_pattern <- function(params, boundary_df, aspect_ratio, legend = FALSE) { args <- as.list(params) args <- args[grep("^pattern_", names(args))] # hexagonal tiling using "regular_polygon" pattern - args$pattern <- "regular_polygon" - args$pattern_density <- 1 - args$pattern_shape <- "convex6" - args$pattern_grid <- "hex" - - if (legend) args$pattern_spacing <- 0.5 * args$pattern_spacing + args$pattern <- "polygon_tiling" # three-color tiling using `fill`, `pattern_fill` and their "average" avg_col <- gridpattern::mean_col(params$fill, params$pattern_fill) - args$pattern_fill <- c(args$pattern_fill, avg_col, params$fill) + args$pattern_fill <- c(params$fill, avg_col, args$pattern_fill) args$x <- boundary_df$x args$y <- boundary_df$y @@ -200,10 +195,13 @@ hex_pattern <- function(params, boundary_df, aspect_ratio, legend = FALSE) { do.call(gridpattern::patternGrob, args) } -options(ggpattern_geometry_funcs = list(hex_tile = hex_pattern)) +options(ggpattern_geometry_funcs = list(tiling3 = tiling3_pattern)) df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2)) ggplot(df, aes(trt, outcome)) + - geom_col_pattern(aes(fill = trt), pattern = 'hex_tile', pattern_angle = 45) + geom_col_pattern(aes(fill = trt, pattern_type = trt), + pattern = 'tiling3', pattern_angle = 45) + + scale_pattern_type_manual(values = c("hexagonal", "tetrakis_square", "rhombille")) + + theme(legend.key.size = unit(1.5, 'cm')) ``` ## Using these patterns with the "piecepackr" package diff --git a/README.md b/README.md index 2486611..572297c 100644 --- a/README.md +++ b/README.md @@ -164,7 +164,7 @@ grid.pattern_weave(x_hex, y_hex, type = "satin", ## Using these patterns with the "ggpattern" package -The patterns provided by ``gridpattern`` can be used to create [custom ggpattern geometry-based patterns](https://coolbutuseless.github.io/package/ggpattern/articles/developing-patterns-2.html). +The patterns provided by ``gridpattern`` can be used to create [custom ggpattern geometry-based patterns](https://coolbutuseless.github.io/package/ggpattern/articles/developing-patterns.html). Here is an example of creating a new "multicolor_stripe" pattern that supports comma-separated ``pattern_fill`` and/or ``pattern_colour`` aesthetics: @@ -201,27 +201,22 @@ ggplot(df, aes(trt, outcome)) + ![](man/figures/README-ggpattern-1.png) -And here is an example of creating a "hex_tile" pattern that creates -a three-color hexagonal tiling using the ``fill`` colour, the ``pattern_fill`` colour, +And here is an example of creating a "tiling3" pattern that creates +three-color polygon tilings using the ``fill`` colour, the ``pattern_fill`` colour, and their "average" color. ```r -hex_pattern <- function(params, boundary_df, aspect_ratio, legend = FALSE) { +tiling3_pattern <- function(params, boundary_df, aspect_ratio, legend = FALSE) { args <- as.list(params) args <- args[grep("^pattern_", names(args))] # hexagonal tiling using "regular_polygon" pattern - args$pattern <- "regular_polygon" - args$pattern_density <- 1 - args$pattern_shape <- "convex6" - args$pattern_grid <- "hex" - - if (legend) args$pattern_spacing <- 0.5 * args$pattern_spacing + args$pattern <- "polygon_tiling" # three-color tiling using `fill`, `pattern_fill` and their "average" avg_col <- gridpattern::mean_col(params$fill, params$pattern_fill) - args$pattern_fill <- c(args$pattern_fill, avg_col, params$fill) + args$pattern_fill <- c(params$fill, avg_col, args$pattern_fill) args$x <- boundary_df$x args$y <- boundary_df$y @@ -231,10 +226,13 @@ hex_pattern <- function(params, boundary_df, aspect_ratio, legend = FALSE) { do.call(gridpattern::patternGrob, args) } -options(ggpattern_geometry_funcs = list(hex_tile = hex_pattern)) +options(ggpattern_geometry_funcs = list(tiling3 = tiling3_pattern)) df <- data.frame(trt = c("a", "b", "c"), outcome = c(2.3, 1.9, 3.2)) ggplot(df, aes(trt, outcome)) + - geom_col_pattern(aes(fill = trt), pattern = 'hex_tile', pattern_angle = 45) + geom_col_pattern(aes(fill = trt, pattern_type = trt), + pattern = 'tiling3', pattern_angle = 45) + + scale_pattern_type_manual(values = c("hexagonal", "tetrakis_square", "rhombille")) + + theme(legend.key.size = unit(1.5, 'cm')) ``` ![](man/figures/README-hex_ggpattern-1.png)