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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Jul 19 22:16:59 CEST 2012


Author: weylandt
Date: 2012-07-19 22:16:58 +0200 (Thu, 19 Jul 2012)
New Revision: 688

Modified:
   pkg/xtsExtra/R/barplot.R
   pkg/xtsExtra/man/barplot.xts.Rd
Log:
Changed one arg of barplot.xts to better match plot.xts; took las= out of formals list

Modified: pkg/xtsExtra/R/barplot.R
===================================================================
--- pkg/xtsExtra/R/barplot.R	2012-07-19 19:11:21 UTC (rev 687)
+++ pkg/xtsExtra/R/barplot.R	2012-07-19 20:16:58 UTC (rev 688)
@@ -19,11 +19,11 @@
 #   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 barplot.xts <- function(height, stacked = TRUE, scale = FALSE, auto.legend = TRUE, 
-                        date.format = "%b %y", ylim=NULL, space = 0.2, cex.axis=0.8,
+                        major.format = TRUE, ylim=NULL, space = 0.2, cex.axis=0.8,
                         cex.legend = 0.8, cex.lab = 1, cex.labels = 0.8, cex.main = 1,
-                        xaxis=TRUE, element.color = "darkgray", xlab="Date",
+                        xaxis=TRUE, box.color = "black", xlab="Date",
                         ylab="Value", major.ticks='auto', minor.ticks=TRUE,
-                        las = 3, xaxis.labels = NULL, col = NULL, ...) {
+                        xaxis.labels = NULL, col = NULL, ...) {
   # Don't like this name for input variable, 
   # but we must match S3 generic so we'll just change it
   x = height 
@@ -49,13 +49,13 @@
     warning("Time-oriented barplot for single observation not well defined.\n  Dispatching instead to unstacked default barplot.")
     # Should I instead let this be forced?
     return(barplot(coredata(x), ylim=NULL, space = 0.2, 
-                   ylab="Value",las = 2, xaxis.labels = xaxis.labels, col = col, ...))
+                   ylab="Value", xaxis.labels = xaxis.labels, col = col, ...))
   }
     
   time.scale = periodicity(x)$scale
-  ep = axTicksByTime(x, major.ticks, format.labels = date.format)
-  ep1 = ep
   
+  ep1 <- ep <- axTicksByTime(x, major.ticks, format.labels = major.format)
+  
   posn = barplot(t(x), plot=FALSE, space=space)
   if(!stacked) posn <- posn*nc
   
@@ -101,31 +101,30 @@
   # t() drops xts-ness and returns a named matrix so dispatches properly
   if(stacked){
     barplot(t(positives), col=col, space=space, axisnames = FALSE, axes = FALSE, ylim=ylim, ...)
-    barplot(t(negatives), add=TRUE, col=col, space=space, las = las, xlab = xlab, cex.names = cex.lab, axes = FALSE, axisnames = FALSE, ylim=ylim, ...)
+    barplot(t(negatives), add=TRUE, col=col, space=space, xlab = xlab, cex.names = cex.lab, axes = FALSE, axisnames = FALSE, ylim=ylim, ...)
   } else {
     barplot(t(x), beside = TRUE, col = col, axes = FALSE, axisnames = FALSE, ylim = ylim, ...)
   }
   
-  axis(2, col = element.color, las = las, cex.axis = cex.axis)
+  axis(2, col = box.color, cex.axis = cex.axis)
   
   title(ylab = ylab, cex = cex.lab)
   
   if (xaxis) {
     if(minor.ticks)
       axis(1, at=posn, labels=FALSE, col='#BBBBBB')
-    label.height = .25 + cex.axis * apply(t(names(ep1)),1, function(X) max(strheight(X, units="in")/par('cin')[2]) )
     
     if(is.null(xaxis.labels))
       xaxis.labels = names(ep1)
     else
       ep1 = 1:length(xaxis.labels)
-    axis(1, at=ep1, labels=xaxis.labels, las=las, lwd=1, mgp=c(3,label.height,0), cex.axis = cex.axis) 
-    #axis(1, at = lab.ind, lab=rownames[lab.ind], cex.axis = cex.axis, col = elementcolor)
+    axis(1, at=ep1, labels=xaxis.labels, lwd=1, mgp=c(3,1.5,0), cex.axis = cex.axis) 
+    #axis(1, at = lab.ind, lab=rownames[lab.ind], cex.axis = cex.axis, col = box.color)
     #             title(xlab = xlab, cex = cex.lab)
     # use axis(..., las=3) for vertical labels.
   }
   
-  box(col = element.color)
+  box(col = box.color)
     
   if(auto.legend){ # For now, only supporting under-legend
     par(mar=c(0,2,0,1)+.1) # set the margins of the second panel
@@ -133,7 +132,7 @@
     
     ncol = min(nc, 4)
     
-    do_barplot.legend("center", legend=colnames(x), cex = cex.legend, fill=col, ncol=ncol, box.col=element.color, border.col = element.color)
+    do_barplot.legend("center", legend=colnames(x), cex = cex.legend, fill=col, ncol=ncol, box.col=box.color, border.col = box.color)
   }
   assign(".barplot.xts",recordPlot(),.GlobalEnv)
   invisible(height)

Modified: pkg/xtsExtra/man/barplot.xts.Rd
===================================================================
--- pkg/xtsExtra/man/barplot.xts.Rd	2012-07-19 19:11:21 UTC (rev 687)
+++ pkg/xtsExtra/man/barplot.xts.Rd	2012-07-19 20:16:58 UTC (rev 688)
@@ -4,20 +4,21 @@
 \description{A barplot method for xts objects.}
 \usage{
 \method{barplot}{xts}(height, stacked = TRUE, scale = FALSE, auto.legend = TRUE, 
-                        date.format = '\%b \%y', ylim=NULL, space = 0.2, cex.axis=0.8,
+                        major.format = TRUE, ylim=NULL, space = 0.2, cex.axis=0.8,
                         cex.legend = 0.8, cex.lab = 1, cex.labels = 0.8, cex.main = 1,
-                        xaxis=TRUE, element.color = "darkgray", xlab="Date",
+                        xaxis=TRUE, box.color = "black", xlab="Date",
                         ylab="Value", major.ticks='auto', minor.ticks=TRUE,
-                        las = 3, xaxis.labels = NULL, col = NULL, ...)
+                        xaxis.labels = NULL, col = NULL, ...)
 }
 \arguments{
   \item{height}{An \code{xts} object of desired frequency. Use \code{to.period}
   functions to aggregate data outside of \code{barplot}.}
   \item{stacked}{logical. Should barplot be stacked?}
   \item{scale}{logical. Should data be rescaled to sum to 100\% at each bar? 
-  Currently does not support negative values.}
+      Currently does not support negative values.}
   \item{auto.legend}{logical. Should a legend be placed underneath the barplot?}
-  \item{date.format}{Format string for x-axis time labels.}
+  \item{major.format}{Format string for x-axis time labels. If \code{TRUE}, 
+      automatically chosen}
   \item{ylim}{Limits of y-axis. If \code{NULL}, sensible defaults are chosen.}
   \item{space}{the amount of space (as a fraction of the
   average bar width) left before each bar, as in
@@ -42,7 +43,7 @@
 
   \item{xaxis}{If true, draws the x axis}
   
-  \item{element.color}{provides the color for drawing
+  \item{box.color}{provides the color for drawing
   less-important chart elements, such as the box lines,
   axis lines, etc.}
 
@@ -57,9 +58,6 @@
   \item{minor.ticks}{Should minor tickmarks be drawn,
   default TRUE}
   
-  \item{las}{Sets orientation of axis labels, as described in \code{\link{par}}. 
-  Here defalts to 3}
-
   \item{xaxis.labels}{Allows for non-date labeling of date
   axes, default is NULL}
 



More information about the Xts-commits mailing list