diff --git a/DESCRIPTION b/DESCRIPTION index c42a5b4a7..d363cdf07 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: ggblanket Title: Simplify 'ggplot2' Visualisation -Version: 9.0.0 +Version: 9.0.0.9000 Authors@R: person("David", "Hodge", , "davidhodge931@gmail.com", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0002-3868-7501")) diff --git a/NEWS.md b/NEWS.md index 27d0816ba..b2e47759a 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# ggblanket 9.0.0.9000 + +* Made pattern guide and label equal to colour/fill align automatically. + # ggblanket 9.0.0 * Supported a label-based workflow. diff --git a/R/gg_blanket.R b/R/gg_blanket.R index bbff94c9b..0e8c8058e 100644 --- a/R/gg_blanket.R +++ b/R/gg_blanket.R @@ -1284,6 +1284,34 @@ gg_blanket <- function(data = NULL, } } } + + if (!rlang::is_null(plot_build$plot$labels$pattern)) { + if (!rlang::is_null(plot_build$plot$labels$colour[1])) { + if (rlang::as_name(plot_build$plot$labels$colour[1]) == rlang::as_name(plot_build$plot$labels$pattern[1])) { + plot <- plot + + ggplot2::guides( + pattern = ggplot2::guide_legend( + reverse = col_legend_rev, + ncol = col_legend_ncol, + nrow = col_legend_nrow + ) + ) + } + } + else if (!rlang::is_null(plot_build$plot$labels$fill[1])) { + if (rlang::as_name(plot_build$plot$labels$fill[1]) == rlang::as_name(plot_build$plot$labels$pattern[1])) { + plot <- plot + + ggplot2::guides( + pattern = ggplot2::guide_legend( + reverse = col_legend_rev, + ncol = col_legend_ncol, + nrow = col_legend_nrow + ) + ) + } + } + } + } #expand limits if necessary @@ -1848,6 +1876,24 @@ gg_blanket <- function(data = NULL, } } else linetype_title <- NULL + if (!rlang::is_null(plot_build$plot$labels$pattern)) { + if (!rlang::is_null(plot_build$plot$labels$colour[1])) { + if (rlang::as_name(plot_build$plot$labels$colour[1]) == rlang::as_name(plot_build$plot$labels$pattern[1])) { + pattern_title <- col_label + } + else pattern_title <- purrr::map_chr(rlang::as_name(plot_build$plot$labels$pattern[1]), label_to_case) + } + else if (!rlang::is_null(plot_build$plot$labels$fill[1])) { + if (rlang::as_name(plot_build$plot$labels$fill[1]) == rlang::as_name(plot_build$plot$labels$pattern[1])) { + pattern_title <- col_label + } + else pattern_title <- purrr::map_chr(rlang::as_name(plot_build$plot$labels$pattern[1]), label_to_case) + } + else { + pattern_title <- purrr::map_chr(rlang::as_name(plot_build$plot$labels$pattern[1]), label_to_case) + } + } else pattern_title <- NULL + plot <- plot + ggplot2::labs( title = title, @@ -1861,7 +1907,9 @@ gg_blanket <- function(data = NULL, shape = shape_title, size = size_title, linewidth = linewidth_title, - linetype = linetype_title + linetype = linetype_title, + + pattern = pattern_title ) ##############################################################################