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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Aug 8 17:33:07 CEST 2012


Author: weylandt
Date: 2012-08-08 17:33:06 +0200 (Wed, 08 Aug 2012)
New Revision: 706

Modified:
   pkg/xtsExtra/R/plot.R
   pkg/xtsExtra/man/plot.xts.Rd
Log:
Two small bug fixes in arg recycling and doc improvements

Modified: pkg/xtsExtra/R/plot.R
===================================================================
--- pkg/xtsExtra/R/plot.R	2012-08-07 18:18:14 UTC (rev 705)
+++ pkg/xtsExtra/R/plot.R	2012-08-08 15:33:06 UTC (rev 706)
@@ -430,7 +430,8 @@
   # Better to do this with xts:::Op etc when moved to xts package?
   
   # Candles -- not happy about lwd fixed: make dynamic / smart?
-  if(candles) rect(.index(x) - width/4, x[,2L], .index(x) + width/4, x[,3L], col = candle.col)
+  if(candles) rect(.index(x) - width/4, x[,2L], .index(x) + width/4, x[,3L], 
+                   col = candle.col, border = candle.col)
   
   # Bars for all OHLC
   rect(.index(x) - width, x[, 1L], .index(x) + width, x[, 4L], 
@@ -450,7 +451,21 @@
 }
 
 get.elm.from.dots <- function(par, dots, screens, n){
-  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)
+  if(!(par %in% names(dots))) {
+    # Return NULL if par is not supplied
+    return(NULL)
+  } else {
+    # Repeat par to length of screens and take n-th screen
+    if(length(screens) == 1L){
+      par <- rep(list(dots[[par]]), length.out = length(screens))
+    } else {
+      par <- rep(dots[[par]], length.out = length(screens))
+    }
+    
+    
+    par <- split(par, screens)
+    
+    j <- n %% length(par)
+    par[[if(j) j else length(par)]]
+  }  
 }
\ No newline at end of file

Modified: pkg/xtsExtra/man/plot.xts.Rd
===================================================================
--- pkg/xtsExtra/man/plot.xts.Rd	2012-08-07 18:18:14 UTC (rev 705)
+++ pkg/xtsExtra/man/plot.xts.Rd	2012-08-08 15:33:06 UTC (rev 706)
@@ -47,9 +47,10 @@
 Care has been taken to make plotting arguments passed by \code{...} behave smartly by classifying them as 'global', 'screen-wise', or 'column-wise' arguments and treating them as such. A partial listing includes:
 \itemize{
   \item Global parameters: \code{main}
-  \item Screen-wise parameters: \code{log}
-  \item Column-wise parameters: \code{col},\code{type},\code{lwd}
+  \item Screen-wise parameters: \code{log}, \code{ylab}
+  \item Column-wise parameters: \code{col},\code{type},\code{lwd}, \code{pch}, \code{cex}
 }
+Arguments that are not set to recycle are applied to all the plots via \code{par} internally; \code{par} is reset to the user's previous state upon exiting the function. 
 
 Better financial plots can be found in the \pkg{quantmod} package, though
 these are generally incompatible with standard R graphics tools.
@@ -66,6 +67,10 @@
 # A candle chart. quantmod does this much better
 plot(sample_xts, type='candles') 
 
+plot(sample_xts[1:30, ], type = "candles")
+
+plot(sample_xts[1:30, ], type = "candles", bar.col.up = "blue", bar.col.dn = "violet", candle.col = "green4")
+
 # By default prefers panels
 plot(sample_xts[,1:2]) 
 
@@ -119,14 +124,14 @@
 # Type = "p" allows for transparent handling of the pch= argument
 x <- xts(1:5, Sys.Date() + 1:5)
 plot(x, type = "p")
-plot(x, type = "p", pch = 1:5)
+plot(x, type = "p", pch = 1:5, col = 1:5)
 
 # Multivariate recycles over columns
-plot(merge(x,x), type = "p", pch = 1:5)
+plot(merge(x,x), type = "p", pch = 1:5, col = 1:2)
 
 # Unless you use a list
-plot(merge(x,x), type = "p", pch = list(1:5))
-plot(merge(x,x,x), type = "p", pch = list(1:5, 1:3))
+plot(merge(x,x), type = "p", pch = list(1:5), col = 1:2)
+plot(merge(x,x,x), type = "p", pch = list(1:5, 1:3), col = 1:3)
 
 # Same for col= and cex= arguments
 plot(x, type = "p", col = 1:5, pch = 1:5, cex = 1:5)
@@ -149,7 +154,15 @@
 # Use of color gradient
 cr <- colorRampPalette(c("#00FF00","#FF0000"))
 plot(sample_xts[,1],sample_xts[,2], xy.labels = FALSE, xy.lines = TRUE, col = cr(NROW(sample_xts)), type = "l")
+
+\dontrun{
+# Some of these will fail because they try to access the 
+# parent frame in ways not congruent with plot.xts
+plot.zoo <- plot.xts
+example(plot.zoo)
+rm(plot.zoo)
 }
+}
 % Add one or more standard keywords, see file 'KEYWORDS' in the
 % R documentation directory.
 \keyword{ hplot }



More information about the Xts-commits mailing list