From 0857be04c1630373ed502a7cb8ff687d465a9232 Mon Sep 17 00:00:00 2001 From: aho Date: Thu, 26 Sep 2019 16:05:06 +0200 Subject: [PATCH 1/5] Modification for review --- R/PlotMatrix.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/PlotMatrix.R b/R/PlotMatrix.R index 32a40c99..748a06ae 100644 --- a/R/PlotMatrix.R +++ b/R/PlotMatrix.R @@ -101,7 +101,7 @@ PlotMatrix <- function(var, brks = NULL, cols = NULL, # If there is any filenames to store the graphics, process them # to select the right device if (!is.null(fileout)) { - deviceInfo <- .SelectDevice(fileout = fileout, + deviceInfo <- s2dverification:::.SelectDevice(fileout = fileout, width = 80 * ncols * figure.width, height = 80 * nrows, units = size_units, res = res) -- GitLab From 81ab4f0422b3e6c0c82286307bbe2b4df3899ece Mon Sep 17 00:00:00 2001 From: ncortesi Date: Fri, 27 Sep 2019 11:51:53 +0200 Subject: [PATCH 2/5] Added two new arguments: xlab_dist and ylab_dist --- man/PlotMatrix.Rd | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/man/PlotMatrix.Rd b/man/PlotMatrix.Rd index 18d15c11..3ab1a85d 100644 --- a/man/PlotMatrix.Rd +++ b/man/PlotMatrix.Rd @@ -8,7 +8,7 @@ PlotMatrix(var, brks = NULL, cols = NULL, toptitle = NULL, title.color = "royalblue4", xtitle = NULL, ytitle = NULL, xlabels = NULL, xvert = FALSE, ylabels = NULL, line = 3, figure.width = 1, legend = TRUE, legend.width = 0.15, fileout = NULL, - size_units = "px", res = 100, ...) + size_units = "px", res = 100, xlab_dist = NULL, ylab_dist = NULL, ...) } \arguments{ \item{var}{A numerical matrix containing the values to be displayed in a @@ -64,6 +64,10 @@ creator function of the corresponding device.} \item{res}{A positive number indicating resolution of the device (file or window) to plot in. See ?Devices and the creator function of the corresponding device.} +\item{xlab_dist}{A number specifying the distance between the x labels and the x axis.} + +\item{ylab_dist}{A number specifying the distance between the y labels and the y axis.} + \item{...}{The additional parameters to be passed to function ColorBar() in s2dverification for color legend creation.} } -- GitLab From 679aa5d1ca74b632adafdae8c31b46ea1875ce8c Mon Sep 17 00:00:00 2001 From: aho Date: Mon, 30 Sep 2019 16:18:14 +0200 Subject: [PATCH 4/5] Add parameter 'xlab_dist' and 'ylab_dist' to PlotMatrix() --- R/PlotMatrix.R | 46 ++++++++++++++++++++++++++++++++++++---------- man/PlotMatrix.Rd | 15 +++++++++------ 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/R/PlotMatrix.R b/R/PlotMatrix.R index 748a06ae..c6395fc6 100644 --- a/R/PlotMatrix.R +++ b/R/PlotMatrix.R @@ -33,6 +33,10 @@ #' Set TRUE as default. #'@param legend.width A number between 0 and 0.5 to adjust the legend width. #' Set 0.15 as default. +#'@param xlab_dist A number specifying the distance between the x labels and +#' the x axis. If not specified, it equals to -1 - (nrow(var) / 10 - 1). +#'@param ylab_dist A number specifying the distance between the y labels and +#' the y axis. If not specified, it equals to 0.5 - ncol(var) / 10. #'@param fileout A string of full directory path and file name indicating where #' to save the plot. If not specified (default), a graphics device will pop up. #'@param size_units A string indicating the units of the size of the device @@ -60,8 +64,8 @@ PlotMatrix <- function(var, brks = NULL, cols = NULL, toptitle = NULL, title.color = "royalblue4", xtitle = NULL, ytitle = NULL, xlabels = NULL, xvert = FALSE, ylabels = NULL, line = 3, figure.width = 1, legend = TRUE, - legend.width = 0.15, fileout = NULL, - size_units = 'px', res = 100, ...) { + legend.width = 0.15, xlab_dist = NULL, ylab_dist = NULL, + fileout = NULL, size_units = 'px', res = 100, ...) { # Check variables: if (!is.matrix(var)) @@ -138,10 +142,21 @@ PlotMatrix <- function(var, brks = NULL, cols = NULL, axis.size <- (max(ncols, nrows) / 10) ^ 0.3 if (is.null(xlabels)) xlabels = 1:ncols if (is.null(ylabels)) ylabels = 1:nrows - axis(1, at = seq(0, ncols - 1), las = ifelse(xvert, 2, 1), labels = xlabels, - cex.axis = axis.size, tck = 0, lwd = 0, line = - 1 - (nrows / 10 - 1)) ## Add x-axis labels - axis(2, at = seq(1, nrows), las = 1, labels = rev(ylabels), - cex.axis = axis.size, tck = 0, lwd = 0, line = 0.5 - ncols / 10) ## Add y-axis labels + + if(is.null(xlab_dist)) { ## Add x axis labels + axis(1, at = seq(0, ncols - 1), las = ifelse(xvert, 2, 1), labels = xlabels, + cex.axis = axis.size, tck = 0, lwd = 0, line = - 1 - (nrows / 10 - 1)) + } else { + axis(1, at = seq(0, ncols - 1), las = ifelse(xvert, 2, 1), labels = xlabels, + cex.axis = axis.size, tck = 0, lwd = 0, line = xlab_dist) + } + if(is.null(ylab_dist)) { ## Add y axis labels + axis(2, at = seq(1, nrows), las = 1, labels = rev(ylabels), + cex.axis = axis.size, tck = 0, lwd = 0, line = 0.5 - ncols / 10) + } else { + axis(2, at = seq(1, nrows), las = 1, labels = rev(ylabels), + cex.axis = axis.size, tck = 0, lwd = 0, line = ylab_dist) + } } else { @@ -164,10 +179,21 @@ PlotMatrix <- function(var, brks = NULL, cols = NULL, axis.size <- 1 #(max(ncols, nrows) / 10) ^ 0.3 if (is.null(xlabels)) xlabels = 1:ncols if (is.null(ylabels)) ylabels = 1:nrows - axis(1, at = seq(0, ncols - 1), las = ifelse(xvert, 2, 1), labels = xlabels, - cex.axis = axis.size, tck = 0, lwd = 0, line = - 1 - (nrows / 10 - 1)) ## Add x-axis labels - axis(2, at = seq(1, nrows), las = 1, labels = rev(ylabels), - cex.axis = axis.size, tck = 0, lwd = 0, line = 0.5 - ncols / 10) ## Add y-axis labels + + if(is.null(xlab_dist)){ ## Add x axis labels + axis(1, at = seq(0, ncols - 1), las = ifelse(xvert, 2, 1), labels = xlabels, + cex.axis = axis.size, tck = 0, lwd = 0, line = - 1 - (nrows / 10 - 1)) + } else { + axis(1, at = seq(0, ncols - 1), las = ifelse(xvert, 2, 1), labels = xlabels, + cex.axis = axis.size, tck = 0, lwd = 0, line = xlab_dist) + } + if(is.null(ylab_dist)){ ## Add y axis labels + axis(2, at = seq(1, nrows), las = 1, labels = rev(ylabels), + cex.axis = axis.size, tck = 0, lwd = 0, line = 0.5 - ncols / 10) + } else { + axis(2, at = seq(1, nrows), las = 1, labels = rev(ylabels), + cex.axis = axis.size, tck = 0, lwd = 0, line = ylab_dist) + } } diff --git a/man/PlotMatrix.Rd b/man/PlotMatrix.Rd index 3ab1a85d..70c1211e 100644 --- a/man/PlotMatrix.Rd +++ b/man/PlotMatrix.Rd @@ -7,8 +7,9 @@ PlotMatrix(var, brks = NULL, cols = NULL, toptitle = NULL, title.color = "royalblue4", xtitle = NULL, ytitle = NULL, xlabels = NULL, xvert = FALSE, ylabels = NULL, line = 3, - figure.width = 1, legend = TRUE, legend.width = 0.15, fileout = NULL, - size_units = "px", res = 100, xlab_dist = NULL, ylab_dist = NULL, ...) + figure.width = 1, legend = TRUE, legend.width = 0.15, + xlab_dist = NULL, ylab_dist = NULL, fileout = NULL, size_units = "px", + res = 100, ...) } \arguments{ \item{var}{A numerical matrix containing the values to be displayed in a @@ -54,6 +55,12 @@ Set TRUE as default.} \item{legend.width}{A number between 0 and 0.5 to adjust the legend width. Set 0.15 as default.} +\item{xlab_dist}{A number specifying the distance between the x labels and +the x axis. If not specified, it equals to -1 - (nrow(var) / 10 - 1).} + +\item{ylab_dist}{A number specifying the distance between the y labels and +the y axis. If not specified, it equals to 0.5 - ncol(var) / 10.} + \item{fileout}{A string of full directory path and file name indicating where to save the plot. If not specified (default), a graphics device will pop up.} @@ -64,10 +71,6 @@ creator function of the corresponding device.} \item{res}{A positive number indicating resolution of the device (file or window) to plot in. See ?Devices and the creator function of the corresponding device.} -\item{xlab_dist}{A number specifying the distance between the x labels and the x axis.} - -\item{ylab_dist}{A number specifying the distance between the y labels and the y axis.} - \item{...}{The additional parameters to be passed to function ColorBar() in s2dverification for color legend creation.} } -- GitLab From ee1cbfb6649d5f2d44ddc776ee3f4da42f8495d8 Mon Sep 17 00:00:00 2001 From: aho Date: Mon, 30 Sep 2019 16:37:08 +0200 Subject: [PATCH 5/5] Add PlotMatrix to NAMESPACE --- NAMESPACE | 1 + 1 file changed, 1 insertion(+) diff --git a/NAMESPACE b/NAMESPACE index 3e35710e..4e855789 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -56,6 +56,7 @@ export(PlotBoxWhisker) export(PlotClim) export(PlotEquiMap) export(PlotLayout) +export(PlotMatrix) export(PlotSection) export(PlotStereoMap) export(PlotVsLTime) -- GitLab