From 3e92c998769d94a0eb91bf462a6a9234b9b4720f Mon Sep 17 00:00:00 2001 From: Jasen Date: Sat, 9 May 2020 11:08:59 -0400 Subject: [PATCH 1/3] Add ylab to plot.xts Few things worth mentioning: 1. Tried to do this in chart.lines() but ylab was not passing through 2. Need a solution for when multi.panel is not NULL, perhaps a character vector of ylab strings? 3. Needed the plot printed before i could add title() hence cs becomes plot(cs) Simple test is add ylab argument to plot.xts() See #333 --- R/plot.R | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/R/plot.R b/R/plot.R index 01474a35..3f02cd48 100644 --- a/R/plot.R +++ b/R/plot.R @@ -131,6 +131,7 @@ plot.xts <- function(x, lwd=2, lend=1, main=deparse(substitute(x)), + ylab=NULL, observation.based=FALSE, ylim=NULL, yaxis.same=TRUE, @@ -557,7 +558,10 @@ plot.xts <- function(x, } } assign(".xts_chob", cs, .plotxtsEnv) - cs + plot(cs) + if(hasArg(ylab)){ + title(ylab = ylab) + } } # apply a function to the xdata in the xts chob and add a panel with the result From 3f2322290a79aad02a59f2f657a5a0edbaaa1693 Mon Sep 17 00:00:00 2001 From: Joshua Ulrich Date: Sun, 10 May 2020 07:55:10 -0500 Subject: [PATCH 2/3] Revert "Add ylab to plot.xts" This reverts commit 3e92c998769d94a0eb91bf462a6a9234b9b4720f. --- R/plot.R | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/R/plot.R b/R/plot.R index 3f02cd48..01474a35 100644 --- a/R/plot.R +++ b/R/plot.R @@ -131,7 +131,6 @@ plot.xts <- function(x, lwd=2, lend=1, main=deparse(substitute(x)), - ylab=NULL, observation.based=FALSE, ylim=NULL, yaxis.same=TRUE, @@ -558,10 +557,7 @@ plot.xts <- function(x, } } assign(".xts_chob", cs, .plotxtsEnv) - plot(cs) - if(hasArg(ylab)){ - title(ylab = ylab) - } + cs } # apply a function to the xdata in the xts chob and add a panel with the result From 4d8b3c6cf91d11117c84b4882de17ba07922d6ca Mon Sep 17 00:00:00 2001 From: Joshua Ulrich Date: Sun, 10 May 2020 06:58:18 -0500 Subject: [PATCH 3/3] Add ylab to plot.xts() --- R/plot.R | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/R/plot.R b/R/plot.R index 01474a35..11b6fcc6 100644 --- a/R/plot.R +++ b/R/plot.R @@ -286,6 +286,7 @@ plot.xts <- function(x, cs$Env$column_names <- colnames(x) cs$Env$nobs <- NROW(cs$Env$xdata) cs$Env$main <- main + cs$Env$ylab <- if (hasArg("ylab")) eval.parent(plot.call$ylab) else "" # Set xlim using the raw returns data passed into function # xlim can be based on observations or time @@ -411,6 +412,10 @@ plot.xts <- function(x, col=theme$labels, srt=theme$srt, offset=1, pos=4, cex=theme$cex.axis, xpd=TRUE))) } + + # ylab + exp <- c(exp, expression(title(ylab = ylab[1], mgp = c(1, 1, 0)))) + cs$add(exp, env=cs$Env, expr=TRUE) # add main series