[Xts-commits] r872 - in pkg/xts: R man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jan 24 19:48:47 CET 2015


Author: rossbennett34
Date: 2015-01-24 19:48:47 +0100 (Sat, 24 Jan 2015)
New Revision: 872

Modified:
   pkg/xts/R/plot.R
   pkg/xts/man/plot.xts.Rd
Log:
added argument to support drawing the x-axis based on the observations in the data or based on the time index of the data

Modified: pkg/xts/R/plot.R
===================================================================
--- pkg/xts/R/plot.R	2015-01-14 13:26:34 UTC (rev 871)
+++ pkg/xts/R/plot.R	2015-01-24 18:48:47 UTC (rev 872)
@@ -263,6 +263,7 @@
                      cex.axis=0.9,
                      mar=c(3,2,0,2), 
                      srt=0,
+                     observation.based=FALSE,
                      xaxis.las=0,
                      ylim=NULL,
                      yaxis.same=TRUE,
@@ -341,6 +342,7 @@
                     cex.axis=cex.axis,
                     mar=mar, 
                     srt=srt,
+                    observation.based=observation.based,
                     xaxis.las=xaxis.las,
                     ylim=ylim,
                     yaxis.same=yaxis.same,
@@ -380,8 +382,6 @@
       x <- "" #1:NROW(Env$xdata)
     }
     Env$xsubset <<- x
-    # set_xlim(c(1,NROW(Env$xdata[Env$xsubset])))
-    # non equally spaced x-axis
     set_xlim(range(Env$xycoords$x, na.rm=TRUE))
     ylim <- get_ylim()
     for(y in seq(2,length(ylim),by=2)) {
@@ -444,6 +444,7 @@
   cs$Env$legend.loc <- legend.loc
   cs$Env$call_list <- list()
   cs$Env$call_list[[1]] <- match.call()
+  cs$Env$observation.based <- observation.based
   
   # Do some checks on x
   if(is.character(x))
@@ -458,12 +459,23 @@
   cs$Env$nobs <- NROW(cs$Env$xdata)
   cs$Env$main <- main
   
-  # non equally spaced x-axis
-  xycoords <- xy.coords(.index(cs$Env$xdata[cs$Env$xsubset]), 
-                        cs$Env$xdata[cs$Env$xsubset][,1])
-  cs$Env$xycoords <- xycoords
-  cs$Env$xlim <- range(xycoords$x, na.rm=TRUE)
-  cs$Env$xstep <- diff(xycoords$x[1:2])
+  # Set xlim using the raw returns data passed into function
+  # xlim can be based on observations or time
+  if(cs$Env$observation.based){
+    # observation based x-axis
+    cs$Env$xycoords <- xy.coords(1:NROW(cs$Env$xdata[subset]))
+    cs$set_xlim(c(1,NROW(cs$Env$xdata[subset])))
+    cs$Env$xstep <- 1
+  } else {
+    # time based x-axis
+    xycoords <- xy.coords(.index(cs$Env$xdata[cs$Env$xsubset]), 
+                          cs$Env$xdata[cs$Env$xsubset][,1])
+    cs$Env$xycoords <- xycoords
+    cs$Env$xlim <- range(xycoords$x, na.rm=TRUE)
+    cs$Env$xstep <- diff(xycoords$x[1:2])
+    # I don't think I need this because I already set cs$Env$xlim
+    cs$set_xlim(cs$Env$xlim)
+  }
   
   # Compute transformation if specified by panel argument
   # rough prototype for calling a function for the main "panel"
@@ -485,12 +497,7 @@
     cs$Env$R <- x
   }
   
-  # Set xlim based on the raw returns data passed into function
-  # cs$set_xlim(c(1,NROW(cs$Env$xdata[subset])))
-  # non equally spaced x-axis
-  cs$set_xlim(cs$Env$xlim)
   
-  
   # Set ylim based on the transformed data
   # chart_Series uses fixed=FALSE and add_* uses fixed=TRUE, not sure why or
   # which is best.

Modified: pkg/xts/man/plot.xts.Rd
===================================================================
--- pkg/xts/man/plot.xts.Rd	2015-01-14 13:26:34 UTC (rev 871)
+++ pkg/xts/man/plot.xts.Rd	2015-01-24 18:48:47 UTC (rev 872)
@@ -8,8 +8,8 @@
   panels = NULL, multi.panel = FALSE, col = 1:12, up.col = "green",
   dn.col = "red", type = "l", lty = 1, lwd = 2, lend = 1,
   main = deparse(substitute(x)), clev = 0, cex = 0.6, cex.axis = 0.9,
-  mar = c(3, 2, 0, 2), srt = 0, xaxis.las = 0, ylim = NULL,
-  yaxis.same = TRUE, yaxis.left = TRUE, yaxis.right = TRUE,
+  mar = c(3, 2, 0, 2), srt = 0, observation.based = FALSE, xaxis.las = 0, 
+  ylim = NULL, yaxis.same = TRUE, yaxis.left = TRUE, yaxis.right = TRUE,
   grid.ticks.on = "months", grid.ticks.lwd = 1, grid.ticks.lty = 1,
   grid.col = "darkgray", labels.col = "#333333", format.labels = TRUE,
   shading = 1, bg.col = "#FFFFFF", grid2 = "#F5F5F5", legend.loc = NULL)
@@ -63,6 +63,8 @@
 
 \item{srt}{rotation for the y axis labels}
 
+\item{observation.based}{TRUE/FALSE (default FALSE). If \code{TRUE}, the x-axis is drawn based on observations in the data. If \code{FALSE}, the x-axis is drawn based on the time index of the data.}
+
 \item{xaxis.las}{rotation for the x axis labels}
 
 \item{ylim}{the range of the y axis}



More information about the Xts-commits mailing list