[Xts-commits] r716 - in pkg/xtsExtra: R man
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Wed Aug 15 05:20:35 CEST 2012
Author: weylandt
Date: 2012-08-15 05:20:35 +0200 (Wed, 15 Aug 2012)
New Revision: 716
Modified:
pkg/xtsExtra/R/plot.R
pkg/xtsExtra/man/plot.xts.Rd
Log:
Change panel functions to act, not surprisingly, panel-wise; required some shenanigans, but it works and is more compatible with plot.zoo
Modified: pkg/xtsExtra/R/plot.R
===================================================================
--- pkg/xtsExtra/R/plot.R 2012-08-14 16:15:41 UTC (rev 715)
+++ pkg/xtsExtra/R/plot.R 2012-08-15 03:20:35 UTC (rev 716)
@@ -22,9 +22,9 @@
yax.loc = c("none", "out", "in", "flip", "left", "right", "top"),
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', panel = lines,
- auto.legend = FALSE, legend.names = colnames(x), legend.loc = "topleft", legend.pars = NULL,
- events, blocks, nc, nr, ...) {
+ xy.labels = FALSE, xy.lines = NULL, ylim = 'auto', panel = 'auto',
+ auto.legend = FALSE, legend.names = colnames(x), legend.loc = "topleft",
+ legend.pars = NULL, events, blocks, nc, nr, ...) {
# Restore old par() options from what I change in here
old.par <- par(no.readonly = TRUE)
@@ -136,7 +136,8 @@
log.panel <- get.elm.from.dots("log", dots, screens, i)
if(is.null(log.panel)) log.panel <- ""
- panel.panel <- match.fun(if(length(panel) > 1L) get.elm.recycle(panel, i) else panel)
+ panel.panel <- if(identical(panel, 'auto')) default.panel else
+ match.fun(if(length(panel) > 1L) get.elm.recycle(panel, i) else panel)
# Note that do_add.grid also sets up axes and what not
do_add.grid(x.plot, major.ticks, major.format, minor.ticks,
@@ -146,7 +147,7 @@
events = events, blocks = blocks,
yax.loc = yax.loc, ylim = get.elm.recycle(ylim, i))
- legend.pars.add <- do_add.lines(x.plot, panel = panel.panel, col = col.panel, lwd = lwd.panel,
+ legend.pars.add <- do_add.panel(x.plot, panel = panel.panel, col = col.panel, lwd = lwd.panel,
pch = pch.panel, type = type.panel, cex = cex.panel, lty = lty.panel)
if(auto.legend && !is.na(get.elm.recycle(legend.loc,i)))
@@ -362,7 +363,7 @@
box()
}
-do_add.lines <- function(x, col, pch, cex, lwd, type, panel, lty, ...){
+do_add.panel <- function(x, col, pch, cex, lwd, type, panel, lty, ...){
if(is.null(col)) col <- 1:NCOL(x)
if(is.null(pch)) pch <- 1
@@ -371,19 +372,9 @@
if(is.null(type)) type <- "l"
if(is.null(lty)) lty <- 1
- for(j in 1:NCOL(x)){
- col.t <- get.elm.recycle(col, j)
- pch.t <- get.elm.recycle(pch, j)
- cex.t <- get.elm.recycle(cex, j)
- lwd.t <- get.elm.recycle(lwd, j)
- type.t <- get.elm.recycle(type, j)
- lty.t <- get.elm.recycle(lty, j)
-
- # Panel function (by default lines.xts) always uses POSIXct for plotting internally
- # No need to special case lines: this formulation emulates lines.xts
- panel(.index(x), x[,j], col = col.t, pch = pch.t, type = type.t,
- lwd = lwd.t, cex = cex.t, lty = lty.t)
- }
+ panel(.index(x), x, col = col, pch = pch, type = type,
+ lwd = lwd, cex = cex, lty = lty)
+
list(col = col, pch = pch, cex = cex, lwd = lwd, type = type, lty = lty)
}
@@ -482,3 +473,18 @@
j <- n %% length(par)
par[[if(j) j else length(par)]]
}
+
+default.panel <- function(index, x, col, pch, cex, lwd, type = type, lty){
+ # This unexported function exists only to provide a
+ # default panel function within plot.xts
+ for(j in seq_len(NCOL(x))){
+ col.t <- get.elm.recycle(col, j)
+ pch.t <- get.elm.recycle(pch, j)
+ cex.t <- get.elm.recycle(cex, j)
+ lwd.t <- get.elm.recycle(lwd, j)
+ type.t <- get.elm.recycle(type, j)
+ lty.t <- get.elm.recycle(lty, j)
+ lines(index, x[,j], col = col.t, pch = pch.t, type = type.t,
+ lwd = lwd.t, cex = cex.t, lty = lty.t)
+ }
+}
\ No newline at end of file
Modified: pkg/xtsExtra/man/plot.xts.Rd
===================================================================
--- pkg/xtsExtra/man/plot.xts.Rd 2012-08-14 16:15:41 UTC (rev 715)
+++ pkg/xtsExtra/man/plot.xts.Rd 2012-08-15 03:20:35 UTC (rev 716)
@@ -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', panel = lines,
+ ylim = 'auto', panel = 'auto',
auto.legend = FALSE, legend.names = colnames(x),
legend.loc = "topleft", legend.pars = NULL,
events, blocks, nc, nr, ...)
@@ -34,7 +34,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; 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. If a list of panel functions is passed, they are recycled panelwise (not serieswise).}
+ \item{panel}{A panel function for plotting; by default, something analogous to \code{lines.xts}. Currently, is passed \code{col}, \code{pch}, \code{type}, \code{lwd}, \code{cex} as calculated internally, so be prepared to handle these arguments, perhaps by receiving them via \code{...} and ignoring. If \code{panel != 'auto'}, that is, if the user supplies a panel function, the first two arguments passed will be \code{as.POSIXct(index(z))} and \code{z} itself, 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 panel, so the second argument (\code{z}) passed may well be a multi-column \code{xts} object; see \code{xts:::auto} for how this is handled by default. If a list of panel functions is passed, they are recycled panelwise.}
\item{auto.legend}{Should a legend be added automatically?}
\item{legend.names}{Names of series to be passed to the legend writing code. Should be one name per series plotted.}
\item{legend.loc}{Location of legend: will be recycled panelwise. If \code{NA}, a legend is ommitted for that panel}
More information about the Xts-commits
mailing list