From 054335d7b0c1058ae8ca081a28e444e8ab4ff6bc Mon Sep 17 00:00:00 2001 From: davidhodge931 Date: Tue, 2 Jul 2024 09:40:59 +1200 Subject: [PATCH] Change *_mode orientation arg to be consistent with that in gg_* functions --- R/dark_mode.R | 24 +++++++++++++++++------- R/flex_mode.R | 36 ++++++++++++++++++++++++++---------- R/light_mode.R | 25 ++++++++++++++++++------- R/set_blanket.R | 2 +- R/weave.R | 2 +- man/dark_mode_r.Rd | 13 +++++++++---- man/flex_mode_b.Rd | 5 ++--- man/flex_mode_base.Rd | 3 ++- man/flex_mode_r.Rd | 5 ++--- man/flex_mode_t.Rd | 5 ++--- man/light_mode_r.Rd | 13 +++++++++---- man/set_blanket.Rd | 2 +- 12 files changed, 90 insertions(+), 45 deletions(-) diff --git a/R/dark_mode.R b/R/dark_mode.R index 9f97607d2..22fa049f6 100644 --- a/R/dark_mode.R +++ b/R/dark_mode.R @@ -27,7 +27,8 @@ #' @param legend_ticks_colour The colour of the legend.ticks theme element. #' @param legend_ticks_linewidth The linewidth of the legend.ticks theme element. #' @param legend_ticks_length The legend.ticks.length theme element. -#' @param orientation The orientation of the plot. Either "x" or "y". Defaults to NULL. Not intended for use with the mode argument of gg_* functions. +#' @param x_orientation TRUE or FALSE for whether it should be orientated to the x axis. Use outside of gg_* functions only. +#' @param y_orientation TRUE or FALSE for whether it should be orientated to the y axis. Use outside of gg_* functions only. #' #' @return A ggplot theme. #' @export @@ -84,7 +85,8 @@ dark_mode_r <- function ( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL) { + x_orientation = NULL, + y_orientation = NULL) { flex_mode_r( base_size = base_size, @@ -122,7 +124,9 @@ dark_mode_r <- function ( legend_ticks_colour = legend_ticks_colour, legend_ticks_linewidth = legend_ticks_linewidth, legend_ticks_length = legend_ticks_length, - orientation = orientation) + x_orientation = x_orientation, + y_orientation = y_orientation + ) } #' @rdname dark_mode_r @@ -149,7 +153,8 @@ dark_mode_t <- function ( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL) { + x_orientation = NULL, + y_orientation = NULL) { flex_mode_t( base_size = base_size, @@ -187,7 +192,9 @@ dark_mode_t <- function ( legend_ticks_colour = legend_ticks_colour, legend_ticks_linewidth = legend_ticks_linewidth, legend_ticks_length = legend_ticks_length, - orientation = orientation) + x_orientation = x_orientation, + y_orientation = y_orientation + ) } #' @rdname dark_mode_r @@ -214,7 +221,8 @@ dark_mode_b <- function ( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL) { + x_orientation = NULL, + y_orientation = NULL) { flex_mode_b( base_size = base_size, @@ -252,5 +260,7 @@ dark_mode_b <- function ( legend_ticks_colour = legend_ticks_colour, legend_ticks_linewidth = legend_ticks_linewidth, legend_ticks_length = legend_ticks_length, - orientation = orientation) + x_orientation = x_orientation, + y_orientation = y_orientation + ) } diff --git a/R/flex_mode.R b/R/flex_mode.R index b037e9157..67bb93bd2 100644 --- a/R/flex_mode.R +++ b/R/flex_mode.R @@ -76,7 +76,8 @@ flex_mode_base <- function( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL + x_orientation = NULL, + y_orientation = NULL ) { theme <- ggplot2::theme( @@ -183,8 +184,17 @@ flex_mode_base <- function( complete = FALSE ) - if (!rlang::is_null(orientation)) { - if (orientation == "x") { + # if (rlang::is_null(x_orientation)) x_orientation <- FALSE + # if (rlang::is_null(y_orientation)) y_orientation <- FALSE + + if (!rlang::is_null(x_orientation) | !rlang::is_null(y_orientation)) { + if (rlang::is_null(x_orientation) & !rlang::is_null(y_orientation)) { + x_orientation <- !y_orientation + } + else if (rlang::is_null(y_orientation) & !rlang::is_null(x_orientation)) { + y_orientation <- !x_orientation + } + if (x_orientation | !y_orientation) { theme <- theme + ggplot2::theme( panel.grid.major.x = ggplot2::element_blank(), @@ -197,7 +207,7 @@ flex_mode_base <- function( axis.minor.ticks.y.right = ggplot2::element_blank() ) } - if (orientation == "y") { + else if (!x_orientation | y_orientation) { theme <- theme + ggplot2::theme( panel.grid.major.y = ggplot2::element_blank(), @@ -261,7 +271,8 @@ flex_mode_r <- function ( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL) { + x_orientation = NULL, + y_orientation = NULL) { flex_mode_base( base_size = base_size, @@ -298,7 +309,8 @@ flex_mode_r <- function ( legend_ticks_colour = legend_ticks_colour, legend_ticks_linewidth = legend_ticks_linewidth, legend_ticks_length = legend_ticks_length, - orientation = orientation + x_orientation = x_orientation, + y_orientation = y_orientation ) } @@ -347,7 +359,8 @@ flex_mode_t <- function ( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL) { + x_orientation = NULL, + y_orientation = NULL) { flex_mode_base( base_size = base_size, @@ -384,7 +397,8 @@ flex_mode_t <- function ( legend_ticks_colour = legend_ticks_colour, legend_ticks_linewidth = legend_ticks_linewidth, legend_ticks_length = legend_ticks_length, - orientation = orientation + x_orientation = x_orientation, + y_orientation = y_orientation ) + ggplot2::theme( legend.position = "top", @@ -448,7 +462,8 @@ flex_mode_b <- function ( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL) { + x_orientation = NULL, + y_orientation = NULL) { flex_mode_base( base_size = base_size, @@ -485,7 +500,8 @@ flex_mode_b <- function ( legend_ticks_colour = legend_ticks_colour, legend_ticks_linewidth = legend_ticks_linewidth, legend_ticks_length = legend_ticks_length, - orientation = orientation + x_orientation = x_orientation, + y_orientation = y_orientation ) + ggplot2::theme( legend.position = "bottom", diff --git a/R/light_mode.R b/R/light_mode.R index 0c17a4fbf..bb5cf1e30 100644 --- a/R/light_mode.R +++ b/R/light_mode.R @@ -27,7 +27,8 @@ #' @param legend_ticks_colour The colour of the legend.ticks theme element. #' @param legend_ticks_linewidth The linewidth of the legend.ticks theme element. #' @param legend_ticks_length The legend.ticks.length theme element. -#' @param orientation The orientation of the plot. Either "x" or "y". Defaults to NULL. Not intended for use with the mode argument of gg_* functions. +#' @param x_orientation TRUE or FALSE for whether it should be orientated to the x axis. Use outside of gg_* functions only. +#' @param y_orientation TRUE or FALSE for whether it should be orientated to the y axis. Use outside of gg_* functions only. #' #' @return A ggplot theme. #' @export @@ -84,7 +85,9 @@ light_mode_r <- function ( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL) { + x_orientation = NULL, + y_orientation = NULL +) { flex_mode_r( base_size = base_size, @@ -122,7 +125,8 @@ light_mode_r <- function ( legend_ticks_colour = legend_ticks_colour, legend_ticks_linewidth = legend_ticks_linewidth, legend_ticks_length = legend_ticks_length, - orientation = orientation + x_orientation = x_orientation, + y_orientation = y_orientation ) } @@ -150,7 +154,9 @@ light_mode_t <- function ( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL) { + x_orientation = NULL, + y_orientation = NULL +) { flex_mode_t( base_size = base_size, @@ -188,7 +194,8 @@ light_mode_t <- function ( legend_ticks_colour = legend_ticks_colour, legend_ticks_linewidth = legend_ticks_linewidth, legend_ticks_length = legend_ticks_length, - orientation = orientation, + x_orientation = x_orientation, + y_orientation = y_orientation ) } @@ -216,7 +223,9 @@ light_mode_b <- function ( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL) { + x_orientation = NULL, + y_orientation = NULL +) { flex_mode_b( base_size = base_size, @@ -254,6 +263,8 @@ light_mode_b <- function ( legend_ticks_colour = legend_ticks_colour, legend_ticks_linewidth = legend_ticks_linewidth, legend_ticks_length = legend_ticks_length, - orientation = orientation) + x_orientation = x_orientation, + y_orientation = y_orientation + ) } diff --git a/R/set_blanket.R b/R/set_blanket.R index e4030f276..dceb9769b 100644 --- a/R/set_blanket.R +++ b/R/set_blanket.R @@ -63,7 +63,7 @@ set_blanket <- function( col_palette_na_c = "#988F88FF", col_palette_o = scales::pal_viridis(option = "G", direction = -1), col_palette_na_o = "#988F88FF", - theme = light_mode_r(orientation = "x")) { + theme = light_mode_r(x_orientation = TRUE)) { weave_mode(new = mode) diff --git a/R/weave.R b/R/weave.R index 2e9b7e173..db6fa60be 100644 --- a/R/weave.R +++ b/R/weave.R @@ -30,7 +30,7 @@ weave_mode <- function(new = light_mode_r()) { #' @param new A ggplot2 theme to be `+`-ed on unmodified to `gg_*` functions. #' #' @noRd -weave_theme <- function(new = light_mode_r(orientation = "x")) { +weave_theme <- function(new = light_mode_r(x_orientation = TRUE)) { old <- ggblanket_global$theme ggblanket_global$theme <- new invisible(old) diff --git a/man/dark_mode_r.Rd b/man/dark_mode_r.Rd index ff5d81b0e..d375dec80 100644 --- a/man/dark_mode_r.Rd +++ b/man/dark_mode_r.Rd @@ -28,7 +28,8 @@ dark_mode_r( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL + x_orientation = NULL, + y_orientation = NULL ) dark_mode_t( @@ -53,7 +54,8 @@ dark_mode_t( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL + x_orientation = NULL, + y_orientation = NULL ) dark_mode_b( @@ -78,7 +80,8 @@ dark_mode_b( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL + x_orientation = NULL, + y_orientation = NULL ) } \arguments{ @@ -124,7 +127,9 @@ dark_mode_b( \item{legend_ticks_length}{The legend.ticks.length theme element.} -\item{orientation}{The orientation of the plot. Either "x" or "y". Defaults to NULL. Not intended for use with the mode argument of gg_* functions.} +\item{x_orientation}{TRUE or FALSE for whether it should be orientated to the x axis. Use outside of gg_* functions only.} + +\item{y_orientation}{TRUE or FALSE for whether it should be orientated to the y axis. Use outside of gg_* functions only.} } \value{ A ggplot theme. diff --git a/man/flex_mode_b.Rd b/man/flex_mode_b.Rd index a13969a86..01af2c93e 100644 --- a/man/flex_mode_b.Rd +++ b/man/flex_mode_b.Rd @@ -40,7 +40,8 @@ flex_mode_b( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL + x_orientation = NULL, + y_orientation = NULL ) } \arguments{ @@ -113,8 +114,6 @@ flex_mode_b( \item{legend_ticks_linewidth}{The linewidth of the legend.ticks theme element.} \item{legend_ticks_length}{The legend.ticks.length theme element.} - -\item{orientation}{The orientation of the plot. Either "x" or "y". Defaults to NULL. Not intended for use with the mode argument of gg_* functions.} } \value{ A ggplot theme. diff --git a/man/flex_mode_base.Rd b/man/flex_mode_base.Rd index 64c5499da..04f0c3963 100644 --- a/man/flex_mode_base.Rd +++ b/man/flex_mode_base.Rd @@ -39,7 +39,8 @@ flex_mode_base( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL + x_orientation = NULL, + y_orientation = NULL ) } \arguments{ diff --git a/man/flex_mode_r.Rd b/man/flex_mode_r.Rd index dfb62aec0..3cd9fc5d0 100644 --- a/man/flex_mode_r.Rd +++ b/man/flex_mode_r.Rd @@ -40,7 +40,8 @@ flex_mode_r( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL + x_orientation = NULL, + y_orientation = NULL ) } \arguments{ @@ -113,8 +114,6 @@ flex_mode_r( \item{legend_ticks_linewidth}{The linewidth of the legend.ticks theme element.} \item{legend_ticks_length}{The legend.ticks.length theme element.} - -\item{orientation}{The orientation of the plot. Either "x" or "y". Defaults to NULL. Not intended for use with the mode argument of gg_* functions.} } \value{ A ggplot theme. diff --git a/man/flex_mode_t.Rd b/man/flex_mode_t.Rd index bda6416df..5cae42994 100644 --- a/man/flex_mode_t.Rd +++ b/man/flex_mode_t.Rd @@ -40,7 +40,8 @@ flex_mode_t( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL + x_orientation = NULL, + y_orientation = NULL ) } \arguments{ @@ -113,8 +114,6 @@ flex_mode_t( \item{legend_ticks_linewidth}{The linewidth of the legend.ticks theme element.} \item{legend_ticks_length}{The legend.ticks.length theme element.} - -\item{orientation}{The orientation of the plot. Either "x" or "y". Defaults to NULL. Not intended for use with the mode argument of gg_* functions.} } \value{ A ggplot theme. diff --git a/man/light_mode_r.Rd b/man/light_mode_r.Rd index 392b554c1..59198ba3d 100644 --- a/man/light_mode_r.Rd +++ b/man/light_mode_r.Rd @@ -28,7 +28,8 @@ light_mode_r( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL + x_orientation = NULL, + y_orientation = NULL ) light_mode_t( @@ -53,7 +54,8 @@ light_mode_t( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL + x_orientation = NULL, + y_orientation = NULL ) light_mode_b( @@ -78,7 +80,8 @@ light_mode_b( legend_ticks_colour = legend_axis_line_colour, legend_ticks_linewidth = legend_axis_line_linewidth, legend_ticks_length = ggplot2::rel(c(0.175, 0)), - orientation = NULL + x_orientation = NULL, + y_orientation = NULL ) } \arguments{ @@ -124,7 +127,9 @@ light_mode_b( \item{legend_ticks_length}{The legend.ticks.length theme element.} -\item{orientation}{The orientation of the plot. Either "x" or "y". Defaults to NULL. Not intended for use with the mode argument of gg_* functions.} +\item{x_orientation}{TRUE or FALSE for whether it should be orientated to the x axis. Use outside of gg_* functions only.} + +\item{y_orientation}{TRUE or FALSE for whether it should be orientated to the y axis. Use outside of gg_* functions only.} } \value{ A ggplot theme. diff --git a/man/set_blanket.Rd b/man/set_blanket.Rd index 3d778126e..b1d988926 100644 --- a/man/set_blanket.Rd +++ b/man/set_blanket.Rd @@ -18,7 +18,7 @@ set_blanket( col_palette_na_c = "#988F88FF", col_palette_o = scales::pal_viridis(option = "G", direction = -1), col_palette_na_o = "#988F88FF", - theme = light_mode_r(orientation = "x") + theme = light_mode_r(x_orientation = TRUE) ) } \arguments{