diff --git a/.Rbuildignore b/.Rbuildignore index fa596e707601da63df8c53cf4f087a70a953dbea..b2d8e5fcebca62bff5e5380a881580283874cd54 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -5,4 +5,4 @@ ./.nc$ .*^(?!data)\.RData$ .*\.gitlab-ci.yml$ -^tests$ +#^tests$ diff --git a/DESCRIPTION b/DESCRIPTION index 07433f279959e102a655e5b3b8d32c51e0a00770..d76276602a8a3d7997e752b9937a613bfbd46167 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: CSTools Title: Assessing Skill of Climate Forecasts on Seasonal-to-Decadal Timescales -Version: 3.1.0 +Version: 4.0.0 Authors@R: c( person("Nuria", "Perez-Zanon", , "nuria.perez@bsc.es", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-8568-3071")), person("Louis-Philippe", "Caron", , "louis-philippe.caron@bsc.es", role = "aut", comment = c(ORCID = "0000-0001-5221-0147")), diff --git a/NEWS.md b/NEWS.md index fab70c708389c95d71195da561f6b346cfed7d2b..722bd0e1cd01e2bb5bde3f63404450c4f2e584c4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,10 @@ +### CSTools 4.0.0 +**Submission date to CRAN: XX-12-2020** +- New features: + + PlotPDFsOLE includes parameters to modify legend style + ### CSTools 3.1.0 -**Submission date to CRAN: XX-06-2020** +**Submission date to CRAN: 02-07-2020** - New features: + EnsClustering vignette diff --git a/R/PlotPDFsOLE.R b/R/PlotPDFsOLE.R index fc4ad76e230b535456f6c6e5aa5930dc42761424..25c669a471bb96392ebfea4cc614764f67e07a1f 100644 --- a/R/PlotPDFsOLE.R +++ b/R/PlotPDFsOLE.R @@ -14,6 +14,10 @@ #' to combining. #' @param nsigma (optional) A numeric value for setting the limits of X axis. #' (Default nsigma = 3). +#' @param legendPos (optional) A character value for setting the position of the +#' legend ("bottom", "top", "right" or "left")(Default 'bottom'). +#' @param legendSize (optional) A numeric value for setting the size of the +#' legend text. (Default 1.0). #' @param plotfile (optional) A filename where the plot will be saved. #' (Default: the plot is not saved). #' @param width (optional) A numeric value indicating the plot width in @@ -40,12 +44,26 @@ #' #' PlotPDFsOLE(pdf_1, pdf_2) #' +#' # Example 2 +#' Glosea5PDF <- c(2.25, 0.67) +#' attr(Glosea5PDF, "name") <- "Glosea5" +#' dim(Glosea5PDF) <- c(statistic = 2) +#' ECMWFPDF <- c(2.38, 0.61) +#' attr(ECMWFPDF, "name") <- "ECMWF" +#' dim(ECMWFPDF) <- c(statistic = 2) +#' MFPDF <- c(4.52, 0.34) +#' attr(MFPDF, "name") <- "MF" +#' dim(MFPDF) <- c(statistic = 2) +#' PlotPDFsOLE(pdf_1 = Glosea5PDF, pdf_2 = ECMWFPDF, legendPos = 'left') +#' PlotPDFsOLE(pdf_1 = Glosea5PDF, pdf_2 = MFPDF, legendPos = 'top') +#' PlotPDFsOLE(pdf_1 = ECMWFPDF, pdf_2 = MFPDF, legendSize = 1.2) + #'@export -PlotPDFsOLE <- function(pdf_1, pdf_2, nsigma = 3, plotfile = NULL, - width = 30, height = 15, - units = "cm", dpi = 300) { +PlotPDFsOLE <- function(pdf_1, pdf_2, nsigma = 3, legendPos = 'bottom', + legendSize = 1.0, plotfile = NULL, width = 30, + height = 15, units = "cm", dpi = 300) { y <- type <- NULL - + if(!is.null(plotfile)){ if (!is.numeric(dpi)) { stop("Parameter 'dpi' must be numeric.") @@ -87,6 +105,15 @@ PlotPDFsOLE <- function(pdf_1, pdf_2, nsigma = 3, plotfile = NULL, "indicating the path and name of output png file.") } } + if (!is.character(legendPos)) { + stop("Parameter 'legendPos' must be character") + } + if(!(legendPos %in% c("bottom", "top", "right", "left"))) { + stop("Parameter 'legendPos' must be equal to 'bottom', 'top', 'right' or 'left'.") + } + if (!is.numeric(legendSize)) { + stop("Parameter 'legendSize' must be numeric.") + } if (!is.numeric(nsigma)) { stop("Parameter 'nsigma' must be numeric.") } @@ -196,14 +223,16 @@ PlotPDFsOLE <- function(pdf_1, pdf_2, nsigma = 3, plotfile = NULL, g <- g + scale_colour_manual(values = cols, limits = c(name1, name2, nameBest), labels = c(label1, label2, labelBest)) + g <- g + theme(plot.title=element_text(size=rel(1.1), colour="black", face= "bold"), axis.text.x = element_text(size=rel(1.2)), axis.text.y = element_text(size=rel(1.2)), axis.title.x = element_blank(), legend.title = element_blank(), - legend.position = c(1,1), legend.justification = c(1,1), - legend.text = element_text(face = "bold")) + legend.position = legendPos, + legend.text = element_text(face = "bold", size=rel(legendSize))) + g <- g + ggtitle(graphicTitle) g <- g + labs(y="probability", size=rel(1.9)) g <- g + stat_function(fun = dnorm_limit, args = list(mean=mean1, sd=sigma1), diff --git a/man/PlotPDFsOLE.Rd b/man/PlotPDFsOLE.Rd index f2e2be8c8c75cd70dabba63accaa5aafbcc37cc3..ff3c568e638a93870726d36d58d29d236c1aa2aa 100644 --- a/man/PlotPDFsOLE.Rd +++ b/man/PlotPDFsOLE.Rd @@ -9,6 +9,8 @@ PlotPDFsOLE( pdf_1, pdf_2, nsigma = 3, + legendPos = "bottom", + legendSize = 1, plotfile = NULL, width = 30, height = 15, @@ -28,6 +30,12 @@ two parameters: mean' and 'standard deviation' of the second gaussian pdf \item{nsigma}{(optional) A numeric value for setting the limits of X axis. (Default nsigma = 3).} +\item{legendPos}{(optional) A character value for setting the position of the +legend ("bottom", "top", "right" or "left")(Default 'bottom').} + +\item{legendSize}{(optional) A numeric value for setting the size of the +legend text. (Default 1.0).} + \item{plotfile}{(optional) A filename where the plot will be saved. (Default: the plot is not saved).} @@ -61,6 +69,19 @@ dim(pdf_2) <- c(statistic = 2) PlotPDFsOLE(pdf_1, pdf_2) +# Example 2 +Glosea5PDF <- c(2.25, 0.67) +attr(Glosea5PDF, "name") <- "Glosea5" +dim(Glosea5PDF) <- c(statistic = 2) +ECMWFPDF <- c(2.38, 0.61) +attr(ECMWFPDF, "name") <- "ECMWF" +dim(ECMWFPDF) <- c(statistic = 2) +MFPDF <- c(4.52, 0.34) +attr(MFPDF, "name") <- "MF" +dim(MFPDF) <- c(statistic = 2) +PlotPDFsOLE(pdf_1 = Glosea5PDF, pdf_2 = ECMWFPDF, legendPos = 'left') +PlotPDFsOLE(pdf_1 = Glosea5PDF, pdf_2 = MFPDF, legendPos = 'top') +PlotPDFsOLE(pdf_1 = ECMWFPDF, pdf_2 = MFPDF, legendSize = 1.2) } \author{ Eroteida Sanchez-Garcia - AEMET, //email{esanchezg@aemet.es} diff --git a/tests/testthat/test-PlotPDFsOLE.R b/tests/testthat/test-PlotPDFsOLE.R index bd1279d9df403c795910d5d9b921f00b6df38592..91e61d08c2c7c08c67d32d70410c1ee9c68f9770 100644 --- a/tests/testthat/test-PlotPDFsOLE.R +++ b/tests/testthat/test-PlotPDFsOLE.R @@ -39,6 +39,22 @@ test_that("Sanity checks", { paste0("Parameter 'plotfile' must be a character string ", "indicating the path and name of output png file.")) + expect_error(PlotPDFsOLE(pdf_1, pdf_2, legendPos = 1, plotfile = NULL, + width = 30, height = 15, + units = "cm", dpi = 300) , + "Parameter 'legendPos' must be character") + + expect_error(PlotPDFsOLE(pdf_1, pdf_2, legendPos = 'arriba', + plotfile = "plot.png", + width = 30, height = 15, + units = "cm", dpi = 300) , + "Parameter 'legendPos' must be equal to 'bottom', 'top', 'right' or 'left'.") + + expect_error(PlotPDFsOLE(pdf_1, pdf_2, legendSize = '3', plotfile = NULL, + width = 30, height = 15, + units = "cm", dpi = 300) , + "Parameter 'legendSize' must be numeric.") + expect_error(PlotPDFsOLE(pdf_1, pdf_2, nsigma = '3', plotfile = NULL, width = 30, height = 15, units = "cm", dpi = 300) ,