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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Aug 7 01:57:02 CEST 2012


Author: weylandt
Date: 2012-08-07 01:57:01 +0200 (Tue, 07 Aug 2012)
New Revision: 700

Modified:
   pkg/xtsExtra/R/plot.R
   pkg/xtsExtra/man/plot.xts.Rd
Log:
Add Panel Function Support

Modified: pkg/xtsExtra/R/plot.R
===================================================================
--- pkg/xtsExtra/R/plot.R	2012-07-31 14:51:55 UTC (rev 699)
+++ pkg/xtsExtra/R/plot.R	2012-08-06 23:57:01 UTC (rev 700)
@@ -20,9 +20,9 @@
 
 `plot.xts` <- function(x, y = NULL, screens = 'auto', layout.screens = 'auto',
       yax.loc = c("none","out","in","flip", "left", "right"), 
-      auto.grid=TRUE, major.ticks='auto', minor.ticks=TRUE, major.format=TRUE, 
+      auto.grid = TRUE, major.ticks = 'auto', minor.ticks = TRUE, major.format = TRUE, 
       bar.col.up = 'white', bar.col.dn ='red', candle.col='black',
-      xy.labels = FALSE, xy.lines = NULL, ylim = 'auto', 
+      xy.labels = FALSE, xy.lines = NULL, ylim = 'auto', panel = lines,
       events, blocks, nc, nr, ...) {
   
   # Restore old par() options from what I change in here
@@ -142,8 +142,10 @@
       lwd.panel  <- get.elm.from.dots("lwd", dots, screens, i)
       type.panel <- get.elm.from.dots("type", dots, screens, i)
       
-      do_add.lines(x.plot, col = col.panel, lwd = lwd.panel, pch = pch.panel, 
-                   type = type.panel, cex = cex.panel)
+      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)
     }
     
   }  
@@ -341,7 +343,7 @@
   box()
 }
 
-do_add.lines <- function(x, col, pch, cex, lwd, type, ...){
+do_add.lines <- function(x, col, pch, cex, lwd, type, panel, ...){
   
   if(is.null(col)) col <- 1:NCOL(x)
   if(is.null(pch)) pch <- 1
@@ -356,7 +358,13 @@
     lwd.t  <- get.elm.recycle(lwd, j)
     type.t <- get.elm.recycle(type, j)
     
-    lines(x[,j], col = col.t, pch = pch.t, type = type.t, lwd = lwd.t, cex = cex.t)
+    if(identical(panel, lines)){
+      panel(x[,j], col = col.t, pch = pch.t, type = type.t, lwd = lwd.t, cex = cex.t)
+    } else {
+      panel(as.POSIXct(index(x)), x[,j], col = col.t, pch = pch.t, type = type.t, lwd = lwd.t, cex = cex.t)
+    }
+    
+    
   }
 }
 
@@ -435,4 +443,4 @@
   if(!(par %in% names(dots))) NULL else 
     get.elm.recycle(split(rep(if(length(levels(screens)) == 1L) list(dots[[par]]) else dots[[par]],
      length.out = length(screens)), screens), n)
-}
+}
\ No newline at end of file

Modified: pkg/xtsExtra/man/plot.xts.Rd
===================================================================
--- pkg/xtsExtra/man/plot.xts.Rd	2012-07-31 14:51:55 UTC (rev 699)
+++ pkg/xtsExtra/man/plot.xts.Rd	2012-08-06 23:57:01 UTC (rev 700)
@@ -12,7 +12,7 @@
             major.format=TRUE, bar.col.up = 'white',
             bar.col.dn ='red', candle.col='black',
             xy.labels = FALSE, xy.lines = NULL, 
-            ylim = 'auto', events, blocks, nc, nr, ...)
+            ylim = 'auto', panel = lines, events, blocks, nc, nr, ...)
 }
 \arguments{
   \item{x}{an \code{xts} object}
@@ -30,6 +30,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{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