From 14f35d24d207850cfe85df80f36fe50be8a65178 Mon Sep 17 00:00:00 2001 From: nperez Date: Fri, 5 Nov 2021 17:43:05 +0100 Subject: [PATCH 1/3] layout parameter --- R/PlotLayout.R | 19 ++++++++++++++++--- man/PlotLayout.Rd | 4 ++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/R/PlotLayout.R b/R/PlotLayout.R index 0d333cb..56ee040 100644 --- a/R/PlotLayout.R +++ b/R/PlotLayout.R @@ -68,6 +68,8 @@ #' than the required the function will stop. By default it is configured to #' arrange the layout in a shape as square as possible. Blank cells can be #' manually populated after with customized plots (see SwitchTofigure). +#'@param layout_order Logical indicating wether the panels should be filled +#' by columns (FALSE) or by raws (TRUE, default). #'@param toptitle Topt title for the multi-pannel. Blank by default. #'@param row_titles Character string vector with titles for each of the rows #' in the layout. Blank by default. @@ -196,7 +198,8 @@ #'@importFrom grDevices dev.cur dev.new dev.off #'@export PlotLayout <- function(fun, plot_dims, var, ..., special_args = NULL, - nrow = NULL, ncol = NULL, toptitle = NULL, + nrow = NULL, ncol = NULL, layout_order = TRUE, + toptitle = NULL, row_titles = NULL, col_titles = NULL, bar_scale = 1, title_scale = 1, title_margin_scale = 1, title_left_shift_scale = 1, @@ -214,7 +217,8 @@ PlotLayout <- function(fun, plot_dims, var, ..., special_args = NULL, fileout = NULL, width = NULL, height = NULL, size_units = 'in', res = 100, close_device = TRUE) { # If there is any filenames to store the graphics, process them - # to select the right device + # to select the right device +print(layout_order) if (!is.null(fileout)) { deviceInfo <- .SelectDevice(fileout = fileout, width = width, height = height, units = size_units, res = res) saveToFile <- deviceInfo$fun @@ -279,6 +283,12 @@ PlotLayout <- function(fun, plot_dims, var, ..., special_args = NULL, } ncol <- round(ncol) } +print(layout_order) + # Check layout_order + if (!is.logical(layout_order)) { + stop("Parameter 'layout_order' must be logical.") + } +print(layout_order) # Check toptitle if (is.null(toptitle) || is.na(toptitle)) { @@ -522,7 +532,9 @@ PlotLayout <- function(fun, plot_dims, var, ..., special_args = NULL, subtitle_cex <- 1.5 * subtitle_scale subtitle_margin <- 0.5 * sqrt(nrow * ncol) * subtitle_cex * subtitle_margin_scale mat_layout <- 1:(nrow * ncol) + ifelse(drawleg != FALSE, 1, 0) - mat_layout <- matrix(mat_layout, nrow, ncol, byrow = TRUE) +print(layout_order) + mat_layout <- matrix(mat_layout, nrow, ncol, byrow = layout_order) +print(mat_layout) fsu <- figure_size_units <- 10 # unitless widths <- rep(fsu, ncol) heights <- rep(fsu, nrow) @@ -556,6 +568,7 @@ PlotLayout <- function(fun, plot_dims, var, ..., special_args = NULL, heights <- c(((title_cex + title_margin) * cs / device_size[2]) * nrow * fsu, heights) } par(oma = extra_margin) +print(mat_layout) layout(mat_layout, widths, heights) # Draw the color bar if (drawleg != FALSE) { diff --git a/man/PlotLayout.Rd b/man/PlotLayout.Rd index 453cf2e..645ddea 100644 --- a/man/PlotLayout.Rd +++ b/man/PlotLayout.Rd @@ -12,6 +12,7 @@ PlotLayout( special_args = NULL, nrow = NULL, ncol = NULL, + layout_order = TRUE, toptitle = NULL, row_titles = NULL, col_titles = NULL, @@ -109,6 +110,9 @@ than the required the function will stop. By default it is configured to arrange the layout in a shape as square as possible. Blank cells can be manually populated after with customized plots (see SwitchTofigure).} +\item{layout_order}{Logical indicating wether the panels should be filled +by columns (FALSE) or by raws (TRUE, default).} + \item{toptitle}{Topt title for the multi-pannel. Blank by default.} \item{row_titles}{Character string vector with titles for each of the rows -- GitLab From 306c58319691285d069ea7f358ee2cde0d1a8833 Mon Sep 17 00:00:00 2001 From: nperez Date: Fri, 5 Nov 2021 17:50:19 +0100 Subject: [PATCH 2/3] change to layout_by_rows --- R/PlotLayout.R | 18 ++++++------------ man/PlotLayout.Rd | 4 ++-- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/R/PlotLayout.R b/R/PlotLayout.R index 56ee040..936dc50 100644 --- a/R/PlotLayout.R +++ b/R/PlotLayout.R @@ -68,7 +68,7 @@ #' than the required the function will stop. By default it is configured to #' arrange the layout in a shape as square as possible. Blank cells can be #' manually populated after with customized plots (see SwitchTofigure). -#'@param layout_order Logical indicating wether the panels should be filled +#'@param layout_by_rows Logical indicating wether the panels should be filled #' by columns (FALSE) or by raws (TRUE, default). #'@param toptitle Topt title for the multi-pannel. Blank by default. #'@param row_titles Character string vector with titles for each of the rows @@ -198,7 +198,7 @@ #'@importFrom grDevices dev.cur dev.new dev.off #'@export PlotLayout <- function(fun, plot_dims, var, ..., special_args = NULL, - nrow = NULL, ncol = NULL, layout_order = TRUE, + nrow = NULL, ncol = NULL, layout_by_rows = TRUE, toptitle = NULL, row_titles = NULL, col_titles = NULL, bar_scale = 1, title_scale = 1, title_margin_scale = 1, @@ -218,7 +218,6 @@ PlotLayout <- function(fun, plot_dims, var, ..., special_args = NULL, size_units = 'in', res = 100, close_device = TRUE) { # If there is any filenames to store the graphics, process them # to select the right device -print(layout_order) if (!is.null(fileout)) { deviceInfo <- .SelectDevice(fileout = fileout, width = width, height = height, units = size_units, res = res) saveToFile <- deviceInfo$fun @@ -283,12 +282,10 @@ print(layout_order) } ncol <- round(ncol) } -print(layout_order) - # Check layout_order - if (!is.logical(layout_order)) { - stop("Parameter 'layout_order' must be logical.") + # Check layout_by_rows + if (!is.logical(layout_by_rows)) { + stop("Parameter 'layout_by_rows' must be logical.") } -print(layout_order) # Check toptitle if (is.null(toptitle) || is.na(toptitle)) { @@ -532,9 +529,7 @@ print(layout_order) subtitle_cex <- 1.5 * subtitle_scale subtitle_margin <- 0.5 * sqrt(nrow * ncol) * subtitle_cex * subtitle_margin_scale mat_layout <- 1:(nrow * ncol) + ifelse(drawleg != FALSE, 1, 0) -print(layout_order) - mat_layout <- matrix(mat_layout, nrow, ncol, byrow = layout_order) -print(mat_layout) + mat_layout <- matrix(mat_layout, nrow, ncol, byrow = layout_by_rows) fsu <- figure_size_units <- 10 # unitless widths <- rep(fsu, ncol) heights <- rep(fsu, nrow) @@ -568,7 +563,6 @@ print(mat_layout) heights <- c(((title_cex + title_margin) * cs / device_size[2]) * nrow * fsu, heights) } par(oma = extra_margin) -print(mat_layout) layout(mat_layout, widths, heights) # Draw the color bar if (drawleg != FALSE) { diff --git a/man/PlotLayout.Rd b/man/PlotLayout.Rd index 645ddea..4482539 100644 --- a/man/PlotLayout.Rd +++ b/man/PlotLayout.Rd @@ -12,7 +12,7 @@ PlotLayout( special_args = NULL, nrow = NULL, ncol = NULL, - layout_order = TRUE, + layout_by_rows = TRUE, toptitle = NULL, row_titles = NULL, col_titles = NULL, @@ -110,7 +110,7 @@ than the required the function will stop. By default it is configured to arrange the layout in a shape as square as possible. Blank cells can be manually populated after with customized plots (see SwitchTofigure).} -\item{layout_order}{Logical indicating wether the panels should be filled +\item{layout_by_rows}{Logical indicating wether the panels should be filled by columns (FALSE) or by raws (TRUE, default).} \item{toptitle}{Topt title for the multi-pannel. Blank by default.} -- GitLab From 1e83f0e25cbe7662ee22f5b8ecc26706c17057a8 Mon Sep 17 00:00:00 2001 From: aho Date: Thu, 18 Nov 2021 18:19:05 +0100 Subject: [PATCH 3/3] Change the order of the new parameter --- R/PlotLayout.R | 9 ++++----- man/PlotLayout.Rd | 8 ++++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/R/PlotLayout.R b/R/PlotLayout.R index 936dc50..50a87f2 100644 --- a/R/PlotLayout.R +++ b/R/PlotLayout.R @@ -68,8 +68,6 @@ #' than the required the function will stop. By default it is configured to #' arrange the layout in a shape as square as possible. Blank cells can be #' manually populated after with customized plots (see SwitchTofigure). -#'@param layout_by_rows Logical indicating wether the panels should be filled -#' by columns (FALSE) or by raws (TRUE, default). #'@param toptitle Topt title for the multi-pannel. Blank by default. #'@param row_titles Character string vector with titles for each of the rows #' in the layout. Blank by default. @@ -124,6 +122,8 @@ #'@param extra_margin Extra margins to be added around the layout, in the #' format c(y1, x1, y2, x2). The units are margin lines. Takes rep(0, 4) #' by default. +#'@param layout_by_rows Logical indicating wether the panels should be filled +#' by columns (FALSE) or by raws (TRUE, default). #'@param fileout File where to save the plot. If not specified (default) a #' graphics device will pop up. Extensions allowed: eps/ps, jpeg, png, pdf, #' bmp and tiff. @@ -198,8 +198,7 @@ #'@importFrom grDevices dev.cur dev.new dev.off #'@export PlotLayout <- function(fun, plot_dims, var, ..., special_args = NULL, - nrow = NULL, ncol = NULL, layout_by_rows = TRUE, - toptitle = NULL, + nrow = NULL, ncol = NULL, toptitle = NULL, row_titles = NULL, col_titles = NULL, bar_scale = 1, title_scale = 1, title_margin_scale = 1, title_left_shift_scale = 1, @@ -213,7 +212,7 @@ PlotLayout <- function(fun, plot_dims, var, ..., special_args = NULL, units = NULL, units_scale = 1, bar_label_scale = 1, bar_tick_scale = 1, bar_extra_margin = rep(0, 4), bar_left_shift_scale = 1, bar_label_digits = 4, - extra_margin = rep(0, 4), + extra_margin = rep(0, 4), layout_by_rows = TRUE, fileout = NULL, width = NULL, height = NULL, size_units = 'in', res = 100, close_device = TRUE) { # If there is any filenames to store the graphics, process them diff --git a/man/PlotLayout.Rd b/man/PlotLayout.Rd index 4482539..10bb39e 100644 --- a/man/PlotLayout.Rd +++ b/man/PlotLayout.Rd @@ -12,7 +12,6 @@ PlotLayout( special_args = NULL, nrow = NULL, ncol = NULL, - layout_by_rows = TRUE, toptitle = NULL, row_titles = NULL, col_titles = NULL, @@ -44,6 +43,7 @@ PlotLayout( bar_left_shift_scale = 1, bar_label_digits = 4, extra_margin = rep(0, 4), + layout_by_rows = TRUE, fileout = NULL, width = NULL, height = NULL, @@ -110,9 +110,6 @@ than the required the function will stop. By default it is configured to arrange the layout in a shape as square as possible. Blank cells can be manually populated after with customized plots (see SwitchTofigure).} -\item{layout_by_rows}{Logical indicating wether the panels should be filled -by columns (FALSE) or by raws (TRUE, default).} - \item{toptitle}{Topt title for the multi-pannel. Blank by default.} \item{row_titles}{Character string vector with titles for each of the rows @@ -184,6 +181,9 @@ disregarded if no 'row_titles' are provided.} format c(y1, x1, y2, x2). The units are margin lines. Takes rep(0, 4) by default.} +\item{layout_by_rows}{Logical indicating wether the panels should be filled +by columns (FALSE) or by raws (TRUE, default).} + \item{fileout}{File where to save the plot. If not specified (default) a graphics device will pop up. Extensions allowed: eps/ps, jpeg, png, pdf, bmp and tiff.} -- GitLab