From 6d124321e8731e6212be4ce878e5480c8509963a Mon Sep 17 00:00:00 2001 From: Frantisek Bartos Date: Fri, 7 Jan 2022 14:23:14 +0100 Subject: [PATCH] Passing xlim and ylim arguments to the `plot.zcurve()` function --- DESCRIPTION | 2 +- NEWS.md | 3 +++ R/main.R | 34 +++++++++++++++++++++++++++++----- man/plot.zcurve.Rd | 2 +- 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 9281269..5dea8b1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: zcurve Title: An Implementation of Z-Curves -Version: 2.1.0 +Version: 2.1.1 Authors@R: c( person("František", "Bartoš", email = "f.bartos96@gmail.com", role = c("aut", "cre")), person("Ulrich", "Schimmack", email = "ulrich.schimmack@utoronto.ca", role = c("aut"))) diff --git a/NEWS.md b/NEWS.md index b7a7aff..4ffc410 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,6 @@ +## version 2.1.1 +- Allowing to pass the xlim and ylim arguments to the z-curve plot function. + ## version 2.1.0 - Adding 'zcurve_data' function to transform different tests statistics into a z-curve data object. diff --git a/R/main.R b/R/main.R index 7a8314f..f7a2658 100644 --- a/R/main.R +++ b/R/main.R @@ -536,7 +536,7 @@ print.summary.zcurve <- function(x, ...){ #' of annotations relative to the figure's width. #' @param cex.anno A number specifying the size of the annotation text. #' @param ... Additional arguments including \code{main}, \code{xlab}, -#' \code{ylab}, \code{cex.axis}, \code{cex.lab} +#' \code{ylab}, \code{xlim}, \code{ylim}, \code{cex.axis}, \code{cex.lab} #' #' @method plot zcurve #' @export plot.zcurve @@ -577,6 +577,16 @@ plot.zcurve <- function(x, annotation = FALSE, CI = FALSE, extrapolate }else{ ylab <- additional$ylab } + if(is.null(additional$xlim)){ + xlim <- NULL + }else{ + xlim <- additional$xlim + } + if(is.null(additional$ylim)){ + ylim <- NULL + }else{ + ylim <- additional$ylim + } if(is.null(additional$cex.axis)){ cex.axis <- 1 }else{ @@ -666,11 +676,25 @@ plot.zcurve <- function(x, annotation = FALSE, CI = FALSE, extrapolate } + # overwrite xmin, xmax, ymin, ymax if xlim and ylim are specified + if(!is.null(ylim)){ + y_min <- ylim[1] + y_max <- ylim[2] + }else{ + y_min <- 0 + } + if(!is.null(xlim)){ + x_min <- xlim[1] + x_max <- xlim[2] + }else{ + x_min <- 0 + } + # plot z-scores used for fitting graphics::plot(h1, freq = FALSE, density = 0, angle = 0, border = "blue", - xlim = c(0, x_max), - ylim = c(0, y_max), + xlim = c(x_min, x_max), + ylim = c(y_min, y_max), ylab = ylab, xlab = xlab, main = main, @@ -682,8 +706,8 @@ plot.zcurve <- function(x, annotation = FALSE, CI = FALSE, extrapolate graphics::par(new=TRUE) graphics::plot(h2, freq = FALSE, density = 0, angle = 0, border ="grey30", - xlim = c(0, x_max), - ylim = c(0, y_max), + xlim = c(x_min, x_max), + ylim = c(y_min, y_max), axes = FALSE, ann = FALSE, lwd = 1, las = 1) } # add the density estimate if the model was estimated by density diff --git a/man/plot.zcurve.Rd b/man/plot.zcurve.Rd index 7714907..582b366 100644 --- a/man/plot.zcurve.Rd +++ b/man/plot.zcurve.Rd @@ -37,7 +37,7 @@ of annotations relative to the figure's width.} \item{cex.anno}{A number specifying the size of the annotation text.} \item{...}{Additional arguments including \code{main}, \code{xlab}, -\code{ylab}, \code{cex.axis}, \code{cex.lab}} +\code{ylab}, \code{xlim}, \code{ylim}, \code{cex.axis}, \code{cex.lab}} } \description{ Plot fitted z-curve object