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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Aug 7 05:57:52 CEST 2012


Author: weylandt
Date: 2012-08-07 05:57:52 +0200 (Tue, 07 Aug 2012)
New Revision: 703

Modified:
   pkg/xtsExtra/R/plot.R
   pkg/xtsExtra/man/plot.xts.Rd
Log:
Added yax.loc = 'top' to plot.xts and accompanying docs; might revise to share x-axes in the future

Modified: pkg/xtsExtra/R/plot.R
===================================================================
--- pkg/xtsExtra/R/plot.R	2012-08-07 03:02:49 UTC (rev 702)
+++ pkg/xtsExtra/R/plot.R	2012-08-07 03:57:52 UTC (rev 703)
@@ -19,7 +19,7 @@
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 `plot.xts` <- function(x, y = NULL, screens = 'auto', layout.screens = 'auto',
-      yax.loc = c("none","out","in","flip", "left", "right"), 
+      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,
@@ -260,6 +260,12 @@
     have_y_axis[] <- TRUE
   }
   
+  if(yax.loc == "top"){
+    ylab.axis[] <- yax.loc
+    have_y_axis[] <- TRUE
+    have_x_axis[] <- TRUE
+  }
+  
   # Moving internal margin code to the panel-wise setup, leaving oma (outer) margin here
   if(length(levels(screens)) > 1L) par(oma = c(1,1,4,1))
   if(yax.loc == "none") par(oma = c(1,4,4,3))
@@ -304,9 +310,10 @@
   } else {
     par(mar = have_x_axis*c(3.4,0,0,0) +
          switch(ylab.axis,
-              none = c(0,0,0,0),
-              left = c(0, 4.5, 0, 1.5), 
-              right = c(0, 1.5, 0, 4.5)))
+              none  = c(0,   0, 0,   0),
+              left  = c(0, 4.5, 0, 1.5), 
+              right = c(0, 1.5, 0, 4.5),
+              top   = c(0, 4.5, 1.5, 1.5)))
   }
   # Plotting Defaults
   if(missing(axes)) axes <- TRUE
@@ -316,7 +323,8 @@
   
   xy <- list(x = .index(x), y = seq(min(x, na.rm = TRUE), max(x, na.rm = TRUE), length.out = NROW(x)))
   plot(xy$x, xy$y, type = "n", axes=FALSE, xlab = xlab, ylab = '', log = log, ylim = ylim)
-  mtext(side = 2 + 2*(ylab.axis == "right"), text = if(ylab.axis == "none") "" else ylab, line = 3, cex = 0.8)
+  mtext(side = 2 + 2*(ylab.axis == "right") + 1*(ylab.axis == "top"), text = if(ylab.axis == "none") "" else ylab, 
+        line = 3 - 2.5*(ylab.axis == "top"), cex = 0.8)
   ep <- axTicksByTime(x, major.ticks, format.labels = major.format)
   
   if(!missing(blocks)){

Modified: pkg/xtsExtra/man/plot.xts.Rd
===================================================================
--- pkg/xtsExtra/man/plot.xts.Rd	2012-08-07 03:02:49 UTC (rev 702)
+++ pkg/xtsExtra/man/plot.xts.Rd	2012-08-07 03:57:52 UTC (rev 703)
@@ -7,7 +7,7 @@
 \usage{
 \method{plot}{xts}(x, y = NULL, 
             screens = 'auto', layout.screens = 'auto',
-            yax.loc = c("none","out","in","flip", "left", "right"),
+            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',
@@ -19,7 +19,8 @@
   \item{y}{an \code{xts} object or \code{NULL}}
   \item{screens}{factor (or coerced to factor) whose levels specify which graph each series is to be plotted in. If not specified, then defaults to a single series per screen for \code{type} not \code{"candles"} or \code{"bars"} See examples.}
   \item{layout.screens}{ Matrix (in a form that could be passed to layout) which arranges screens.}
-  \item{yax.loc}{Where to put y-axis labels if they are to be drawn.}
+  \item{yax.loc}{Where to put y-axis labels if they are to be drawn? \code{'none'}, \code{'left'},\code{'right'} are rather self-evident. \code{'in'} and \code{'out'} currently only work for two column layouts. \code{'flip'} attemps to arrange the axes to alternate between the left and right hand sides of the plot to avoid label collision. \code{'top'} is something of a misnomer: it places the y-axis labels above each panel while leaving all plots with their own x- and y-axes. 
+  }
   \item{auto.grid}{should grid lines be drawn}
   \item{major.ticks}{should major tickmarks be drawn and labeled}
   \item{minor.ticks}{should minor tickmarks be drawn}
@@ -108,9 +109,13 @@
 plot(sample_xts, layout = matrix(1:4, ncol = 2), yax.loc = "out")
 plot(sample_xts, layout = matrix(1:4, ncol = 2), yax.loc = "flip")
 
-plot(sample_xts[,c(1:4, 3:4)], layout = matrix(c(1,1,1,1,2,2,3,4,5,6), ncol = 2, byrow = TRUE), yax.loc = "in")
+plot(sample_xts[,c(1:4, 3:4)], layout = matrix(c(1,1,1,1,2,2,3,4,5,6), ncol = 2, byrow = TRUE), yax.loc = "flip")
 
+plot(sample_xts[,c(1:4, 3:4)], layout = matrix(c(1,1,1,1,2,2,3,4,5,6), ncol = 2, byrow = TRUE), yax.loc = "left")
 
+plot(sample_xts[,c(1:4, 3:4)], layout = matrix(c(1,1,1,1,2,2,3,4,5,6), ncol = 2, byrow = TRUE), yax.loc = "top")
+
+
 # Type = "p" allows for transparent handling of the pch= argument
 x <- xts(1:5, Sys.Date() + 1:5)
 plot(x, type = "p")



More information about the Xts-commits mailing list