Skip to content

Commit

Permalink
Fix #867
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhodge931 committed May 18, 2024
1 parent 0ecc1b7 commit 5fd75b1
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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"))
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
50 changes: 49 additions & 1 deletion R/gg_blanket.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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
)

##############################################################################
Expand Down

0 comments on commit 5fd75b1

Please sign in to comment.