[Xts-commits] r704 - in pkg/xtsExtra: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Aug 7 19:00:29 CEST 2012


Author: weylandt
Date: 2012-08-07 19:00:28 +0200 (Tue, 07 Aug 2012)
New Revision: 704

Modified:
   pkg/xtsExtra/R/plot.R
   pkg/xtsExtra/man/plot.xts.Rd
Log:
Better handling of some ... args like fg and bg; doc clarification re panel func indices

Modified: pkg/xtsExtra/R/plot.R
===================================================================
--- pkg/xtsExtra/R/plot.R	2012-08-07 03:57:52 UTC (rev 703)
+++ pkg/xtsExtra/R/plot.R	2012-08-07 17:00:28 UTC (rev 704)
@@ -32,6 +32,9 @@
   on.exit(assign(".plot.xts", recordPlot(), .GlobalEnv), add = TRUE)
   
   dots <- list(...)
+  
+  do.call(par, dots[!(names(dots) %in% 
+    c("col", "type", "lwd", "pch", "log", "cex", "ylab", "main", "axes", "xlab"))])
    
   ## if y supplied: scatter plot y ~ x
   if(!is.null(y)) {
@@ -116,19 +119,21 @@
     for(i in seq_along(levels((screens)))){
       x.plot <- x.split[[i]]
     
-      # Handle the screen-wise parameters here
-      if("ylab" %in% names(dots)) {
-        ylab.panel <- get.elm.recycle(dots[["ylab"]],i)
-      } else {
-        ylab.panel <- if(!is.null(colnames(x.plot)[[1]])) colnames(x.plot)[[1]] else ""
-      }
-        
-      if("log" %in% names(dots)){
-        log.panel <- get.elm.recycle(dots[["log"]],i)
-      } else {
-        log.panel <- ""
-      }
+      col.panel  <- get.elm.from.dots("col", dots, screens, i)
+      pch.panel  <- get.elm.from.dots("pch", dots, screens, i)
+      cex.panel  <- get.elm.from.dots("cex", dots, screens, i)
+      lwd.panel  <- get.elm.from.dots("lwd", dots, screens, i)
+      type.panel <- get.elm.from.dots("type", dots, screens, i)
       
+      # Set these defaults here
+      ylab.panel <- get.elm.from.dots("ylab", dots, screens, i)
+      if(is.null(ylab.panel)) ylab.panel <- if(!is.null(colnames(x.plot)[[1]])) colnames(x.plot)[[1]] else ""
+      
+      log.panel <- get.elm.from.dots("log", dots, screens, i)
+      if(is.null(log.panel)) log.panel <- ""
+      
+      panel <- match.fun(panel)
+      
       # Note that do_add.grid also sets up axes and what not
       do_add.grid(x.plot, major.ticks, major.format, minor.ticks, 
             auto.grid = auto.grid, ylab = ylab.panel, log = log.panel, 
@@ -137,15 +142,6 @@
             events = events, blocks = blocks,
             yax.loc = yax.loc, ylim = get.elm.recycle(ylim, i))
       
-      
-      col.panel  <- get.elm.from.dots("col", dots, screens, i)
-      pch.panel  <- get.elm.from.dots("pch", dots, screens, i)
-      cex.panel  <- get.elm.from.dots("cex", dots, screens, i)
-      lwd.panel  <- get.elm.from.dots("lwd", dots, screens, i)
-      type.panel <- get.elm.from.dots("type", dots, screens, i)
-      
-      panel <- match.fun(panel)
-      
       do_add.lines(x.plot, panel = panel, col = col.panel, lwd = lwd.panel, 
                    pch = pch.panel, type = type.panel, cex = cex.panel)
     }
@@ -155,7 +151,9 @@
   return(invisible(reclass(x)))
 }
 
-do_scatterplot <- function(x, y, xy.labels, xy.lines, xlab, ylab, main, log, cex, xlim, ylim, type, pch, col, ...){
+do_scatterplot <- function(x, y, xy.labels, xy.lines, xlab, ylab, main, 
+                           log, cex, xlim, ylim, type, pch, col, ...){
+  
   if(missing(main)) main <- paste(xlab, "vs.", ylab)
   if(missing(log))  log  <- ''
   if(missing(cex))  cex  <- 0.8
@@ -183,7 +181,8 @@
   plot(xy[1:2], type = ptype, main = main, xlab = xlab, 
         ylab = ylab, xlim = xlim, ylim = ylim, log = log, pch = pch, col = col)
 
-  if(do.lab) text(xy[1:2], cex = cex, labels = if(!is.logical(xy.labels)) xy.labels else index2char(index(xy.xts)), col = col)
+  if(do.lab) text(xy[1:2], cex = cex, labels = if(!is.logical(xy.labels)) 
+    xy.labels else index2char(index(xy.xts)), col = col)
   
   if(xy.lines) segments(xy[[1]][-NROW(xy[[1]])],xy[[2]][-NROW(xy[[2]])], 
                      xy[[1]][-1],xy[[2]][-1], col = col)

Modified: pkg/xtsExtra/man/plot.xts.Rd
===================================================================
--- pkg/xtsExtra/man/plot.xts.Rd	2012-08-07 03:57:52 UTC (rev 703)
+++ pkg/xtsExtra/man/plot.xts.Rd	2012-08-07 17:00:28 UTC (rev 704)
@@ -31,7 +31,7 @@
   \item{xy.labels}{label points in scatterplot?}
   \item{xy.lines}{connect points in scatterplot?}
   \item{ylim}{How to handle \code{ylim} for plots. If \code{'fixed'} all panels share \code{ylim = range(x)}; if \code{'auto'} panels sharing a y axis have the same limits. If a numeric matrix, rows are recycled panel-wise as \code{ylim}.}
-  \item{panel}{A panel function for plotting; by default, \code{lines.xts}. Currently, is passed \code{col}, \code{pch}, \code{type}, \code{lwd}, \code{cex} by default so be prepared to handle these arguments, perhaps by receiving them via \code{...} and ignoring. If \code{panel != lines}, that is, if the user supplies a panel function, the first two arguments passed will be \code{as.POSIXct(index(z))} and \code{coredata(z)} where \code{z} is the series being plotted in that panel. Note further that \code{panel} is called for each series individually, even if they share a screen.}
+  \item{panel}{A panel function for plotting; by default, \code{lines.xts}. Currently, is passed \code{col}, \code{pch}, \code{type}, \code{lwd}, \code{cex} by default so be prepared to handle these arguments, perhaps by receiving them via \code{...} and ignoring. If \code{panel != lines}, that is, if the user supplies a panel function, the first two arguments passed will be \code{as.POSIXct(index(z))} and \code{coredata(z)} where \code{z} is the series being plotted in that panel; as a result, note that any plotting inside \code{panel} requires \code{POSIXct}, regardless of the index class of \code{x}. Note further that \code{panel} is called for each series individually, even if they share a screen.}
   \item{events}{A list with mandatory elements \code{time} and \code{label} and optional 
   elements \code{col} and \code{lty} giving the events to be highlighted. See examples.}
   \item{blocks}{A list with mandatory elements \code{start.time} and \code{end.time} and 



More information about the Xts-commits mailing list