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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jun 24 18:54:45 CEST 2012


Author: weylandt
Date: 2012-06-24 18:54:45 +0200 (Sun, 24 Jun 2012)
New Revision: 653

Modified:
   pkg/xtsExtra/R/plot.R
   pkg/xtsExtra/man/plot.xts.Rd
Log:
Added up/down colors for OHLC bars

Modified: pkg/xtsExtra/R/plot.R
===================================================================
--- pkg/xtsExtra/R/plot.R	2012-06-22 04:40:55 UTC (rev 652)
+++ pkg/xtsExtra/R/plot.R	2012-06-24 16:54:45 UTC (rev 653)
@@ -50,8 +50,8 @@
                        screens = 'auto', layout.screens = 'auto',
                        auto.grid=TRUE,
                        major.ticks='auto', minor.ticks=TRUE, 
-                       major.format=TRUE,
-                       bar.col='black', candle.col='red',
+                       major.format=TRUE, bar.col.up = 'white',
+                       bar.col.dn ='black', candle.col='black',
                        xy.labels = FALSE, xy.lines = NULL,
                        ...) {
   
@@ -105,9 +105,11 @@
     
     if(!xts:::is.OHLC(x)) stop(type, '-chart not supported for non-OHLC series')
     
-    do_plot.ohlc(x, bar.col = bar.col, candle.col = candle.col, 
-          major.ticks = major.ticks, minor.ticks = minor.ticks, 
-          auto.grid = auto.grid, major.format = major.format, main = main, candles = (type == "candles"), ...)
+    do_plot.ohlc(x, bar.col.up = bar.col.up, bar.col.dn = bar.col.dn, 
+                 candle.col = candle.col, major.ticks = major.ticks, 
+                 minor.ticks = minor.ticks, auto.grid = auto.grid, 
+                 major.format = major.format, main = main, 
+                 candles = (type == "candles"), ...)
   } else {  
     # Else need to do layout plots
     screens <- do_layout(x, screens = screens, layout.screens = layout.screens)
@@ -299,7 +301,7 @@
 
 do_add.legend <- function(){}
 
-do_plot.ohlc <- function(x, bar.col, candle.col, major.ticks, 
+do_plot.ohlc <- function(x, bar.col.up, bar.col.dn, candle.col, major.ticks, 
                                  minor.ticks, major.format, auto.grid, candles, ...){
   
   if(QUANTMOD_MESSAGE) {
@@ -326,7 +328,7 @@
   
   # Bars for all OHLC
   rect(.index(x) - width, x[, 1L], .index(x) + width, x[, 4L], 
-       col = bar.col, border = bar.col)
+       col = ifelse(x[,4L] > x[,1L], bar.col.up, bar.col.dn), border = candle.col)
   
   return(invisible(reclass(x)))
 }

Modified: pkg/xtsExtra/man/plot.xts.Rd
===================================================================
--- pkg/xtsExtra/man/plot.xts.Rd	2012-06-22 04:40:55 UTC (rev 652)
+++ pkg/xtsExtra/man/plot.xts.Rd	2012-06-24 16:54:45 UTC (rev 653)
@@ -6,12 +6,12 @@
 }
 \usage{
 \method{plot}{xts}(x, y = NULL, 
-                	screens = 'auto', layout.screens = 'auto',
-                	auto.grid=TRUE,
-                    major.ticks='auto', minor.ticks=TRUE, 
-                    major.format=TRUE,
-                    bar.col='black', candle.col='red',
-                    xy.labels = FALSE, xy.lines = NULL, 
+                       screens = 'auto', layout.screens = 'auto',
+                       auto.grid=TRUE,
+                       major.ticks='auto', minor.ticks=TRUE, 
+                       major.format=TRUE, bar.col.up = 'white',
+                       bar.col.dn ='black', candle.col='black',
+                       xy.labels = FALSE, xy.lines = NULL,
                        ...)
 }
 \arguments{
@@ -23,8 +23,9 @@
   \item{major.ticks}{should major tickmarks be drawn and labeled}
   \item{minor.ticks}{should minor tickmarks be drawn}
   \item{major.format}{passed along to axTicksByTime.}
-  \item{bar.col}{the color of the bars when type is \sQuote{bars} or \sQuote{candles}}
-  \item{candle.col}{the color of the candles when type is \sQuote{candles}}
+  \item{bar.col.dn}{the color of the \dQuote{down} bars when \code{type} is \sQuote{bars} or \sQuote{candles}}
+  \item{bar.col.up}{the color of the \dQuote{up} bars when \code{type} is \sQuote{bars} or \sQuote{candles}}
+  \item{candle.col}{the color of the candles when \code{type} is \sQuote{candles}. Also the outside of the bars.}
   \item{xy.labels}{label points in scatterplot?}
   \item{xy.lines}{connect points in scatterplot?}
   \item{\dots}{additional graphical arguments}



More information about the Xts-commits mailing list