From noreply at r-forge.r-project.org Sat Jan 10 15:55:05 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 10 Jan 2015 15:55:05 +0100 (CET) Subject: [Xts-commits] r868 - in pkg/xts: . R man Message-ID: <20150110145505.BBF60187048@r-forge.r-project.org> Author: rossbennett34 Date: 2015-01-10 15:55:05 +0100 (Sat, 10 Jan 2015) New Revision: 868 Added: pkg/xts/man/addEventLines.Rd Removed: pkg/xts/man/addLines.Rd Modified: pkg/xts/NAMESPACE pkg/xts/R/plot.R Log: rename addLines to addEventLines to avoid confusion with lines and addSeries Modified: pkg/xts/NAMESPACE =================================================================== --- pkg/xts/NAMESPACE 2014-12-30 03:36:30 UTC (rev 867) +++ pkg/xts/NAMESPACE 2015-01-10 14:55:05 UTC (rev 868) @@ -121,7 +121,7 @@ export(plot.xts) export(addLegend) -export(addLines) +export(addEventLines) export(addPoints) export(addSeries) S3method(plot,xts) Modified: pkg/xts/R/plot.R =================================================================== --- pkg/xts/R/plot.R 2014-12-30 03:36:30 UTC (rev 867) +++ pkg/xts/R/plot.R 2015-01-10 14:55:05 UTC (rev 868) @@ -896,7 +896,7 @@ #' @param col color palette to use, set by default to rational choices. #' @param \dots any other passthrough parameters. Not currently used. #' @author Ross Bennett -addLines <- function(event.dates, event.labels=NULL, date.format="%Y-%m-%d", main="", on=NA, lty=1, lwd=1, col=1, ...){ +addEventLines <- function(event.dates, event.labels=NULL, date.format="%Y-%m-%d", main="", on=NA, lty=1, lwd=1, col=1, ...){ # add checks for event.dates and event.labels if(!is.null(event.labels)) if(length(event.dates) != length(event.labels)) stop("length of event.dates must match length of event.labels") Added: pkg/xts/man/addEventLines.Rd =================================================================== --- pkg/xts/man/addEventLines.Rd (rev 0) +++ pkg/xts/man/addEventLines.Rd 2015-01-10 14:55:05 UTC (rev 868) @@ -0,0 +1,40 @@ +% Generated by roxygen2 (4.0.1): do not edit by hand +\name{addEventLines} +\alias{addEventLines} +\title{Add vertical lines to an existing xts plot} +\usage{ +addEventLines(event.dates, event.labels = NULL, date.format = "\%Y-\%m-\%d", + main = "", on = NA, lty = 1, lwd = 1, col = 1, ...) +} +\arguments{ +\item{event.dates}{character vector of dates. Vertical lines will be drawn +to indicate that an event happened during that time period. \code{event.lines} should +be a vector of dates (e.g., \code{c("09/03","05/06"))} formatted the same as +\code{date.format}. This function matches the re-formatted row names (dates) with +the events.list, so to get a match the formatting needs to be correct.} + +\item{event.labels}{character vector of event labels corresponding to +\code{event.dates}. This will apply text labels (e.g., +\code{c("This Event", "That Event")} to the vertical lines drawn.} + +\item{date.format}{format for the dates in \code{event.lines}.} + +\item{main}{main title for a new panel if drawn.} + +\item{on}{panel number to draw on. A new panel will be drawn if \code{on=NA}.} + +\item{lty}{set the line type, same as in \code{\link{plot}}.} + +\item{lwd}{set the line width, same as in \code{\link{plot}}.} + +\item{col}{color palette to use, set by default to rational choices.} + +\item{\dots}{any other passthrough parameters. Not currently used.} +} +\description{ +Add vertical lines to an existing xts plot +} +\author{ +Ross Bennett +} + Deleted: pkg/xts/man/addLines.Rd =================================================================== --- pkg/xts/man/addLines.Rd 2014-12-30 03:36:30 UTC (rev 867) +++ pkg/xts/man/addLines.Rd 2015-01-10 14:55:05 UTC (rev 868) @@ -1,40 +0,0 @@ -% Generated by roxygen2 (4.0.1): do not edit by hand -\name{addLines} -\alias{addLines} -\title{Add vertical lines to an existing xts plot} -\usage{ -addLines(event.dates, event.labels = NULL, date.format = "\%Y-\%m-\%d", - main = "", on = NA, lty = 1, lwd = 1, col = 1, ...) -} -\arguments{ -\item{event.dates}{character vector of dates. Vertical lines will be drawn -to indicate that an event happened during that time period. \code{event.lines} should -be a vector of dates (e.g., \code{c("09/03","05/06"))} formatted the same as -\code{date.format}. This function matches the re-formatted row names (dates) with -the events.list, so to get a match the formatting needs to be correct.} - -\item{event.labels}{character vector of event labels corresponding to -\code{event.dates}. This will apply text labels (e.g., -\code{c("This Event", "That Event")} to the vertical lines drawn.} - -\item{date.format}{format for the dates in \code{event.lines}.} - -\item{main}{main title for a new panel if drawn.} - -\item{on}{panel number to draw on. A new panel will be drawn if \code{on=NA}.} - -\item{lty}{set the line type, same as in \code{\link{plot}}.} - -\item{lwd}{set the line width, same as in \code{\link{plot}}.} - -\item{col}{color palette to use, set by default to rational choices.} - -\item{\dots}{any other passthrough parameters. Not currently used.} -} -\description{ -Add vertical lines to an existing xts plot -} -\author{ -Ross Bennett -} - From noreply at r-forge.r-project.org Sat Jan 10 16:40:11 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 10 Jan 2015 16:40:11 +0100 (CET) Subject: [Xts-commits] r869 - in pkg/xts: . R man Message-ID: <20150110154011.AFAC9183CE7@r-forge.r-project.org> Author: rossbennett34 Date: 2015-01-10 16:40:11 +0100 (Sat, 10 Jan 2015) New Revision: 869 Added: pkg/xts/man/lines.xts.Rd pkg/xts/man/points.xts.Rd Removed: pkg/xts/man/addPoints.Rd Modified: pkg/xts/NAMESPACE pkg/xts/R/plot.R Log: Add S3 methods for lines.xts and points.xts s/addPoints/points.xts Modified: pkg/xts/NAMESPACE =================================================================== --- pkg/xts/NAMESPACE 2015-01-10 14:55:05 UTC (rev 868) +++ pkg/xts/NAMESPACE 2015-01-10 15:40:11 UTC (rev 869) @@ -122,9 +122,11 @@ export(plot.xts) export(addLegend) export(addEventLines) -export(addPoints) +# export(addPoints) export(addSeries) S3method(plot,xts) +S3method(lines,xts) +S3method(points,xts) S3method(print, replot_xts) S3method(plot, replot_xts) Modified: pkg/xts/R/plot.R =================================================================== --- pkg/xts/R/plot.R 2015-01-10 14:55:05 UTC (rev 868) +++ pkg/xts/R/plot.R 2015-01-10 15:40:11 UTC (rev 869) @@ -865,6 +865,15 @@ plot_object } +lines.xts <- function(x, ..., main="", on=NA, col=NULL, lty=1, lwd=1, pch=0){ + addSeries(x, ...=..., main=main, on=on, type="l", col=col, lty=lty, lwd=lwd, pch=pch) +} + + +# addPoints <- function(x, main="", on=NA, col=NULL, pch=0, ...){ +# addSeries(x, main=main, on=on, type="p", col=col, pch=pch, ...) +# } + #' Add time series of points to an existing xts plot #' #' @param x an xts object to plot. @@ -874,8 +883,8 @@ #' @param pch the type of plot to be drawn, same as in \code{\link{plot}}. #' @param \dots any other passthrough parameters. Not currently used. #' @author Ross Bennett -addPoints <- function(x, main="", on=NA, col=NULL, pch=0, ...){ - addSeries(x, main=main, on=on, type="p", col=col, pch=pch, ...) +points.xts <- function(x, ..., main="", on=NA, col=NULL, pch=0){ + addSeries(x, ...=..., main=main, on=on, type="p", col=col, pch=pch) } #' Add vertical lines to an existing xts plot Deleted: pkg/xts/man/addPoints.Rd =================================================================== --- pkg/xts/man/addPoints.Rd 2015-01-10 14:55:05 UTC (rev 868) +++ pkg/xts/man/addPoints.Rd 2015-01-10 15:40:11 UTC (rev 869) @@ -1,27 +0,0 @@ -% Generated by roxygen2 (4.0.1): do not edit by hand -\name{addPoints} -\alias{addPoints} -\title{Add time series of points to an existing xts plot} -\usage{ -addPoints(x, main = "", on = NA, col = NULL, pch = 0, ...) -} -\arguments{ -\item{x}{an xts object to plot.} - -\item{main}{main title for a new panel if drawn.} - -\item{on}{panel number to draw on. A new panel will be drawn if \code{on=NA}.} - -\item{col}{color palette to use, set by default to rational choices.} - -\item{pch}{the type of plot to be drawn, same as in \code{\link{plot}}.} - -\item{\dots}{any other passthrough parameters. Not currently used.} -} -\description{ -Add time series of points to an existing xts plot -} -\author{ -Ross Bennett -} - Added: pkg/xts/man/lines.xts.Rd =================================================================== --- pkg/xts/man/lines.xts.Rd (rev 0) +++ pkg/xts/man/lines.xts.Rd 2015-01-10 15:40:11 UTC (rev 869) @@ -0,0 +1,30 @@ +\name{lines.xts} +\alias{lines.xts} +\title{Add time series lines to an existing xts plot} +\usage{ +\method{lines}{xts}(x, ..., main = "", on = NA, col = NULL, lty = 1, + lwd = 1, pch = 0) +} +\arguments{ +\item{x}{an xts object to plot.} + +\item{\dots}{any other passthrough parameters. Not currently used.} + +\item{main}{main title for a new panel if drawn.} + +\item{on}{panel number to draw on. A new panel will be drawn if \code{on=NA}.} + +\item{col}{color palette to use, set by default to rational choices.} + +\item{lty}{set the line type, same as in \code{\link{plot}}.} + +\item{lwd}{set the line width, same as in \code{\link{plot}}.} + +\item{pch}{the type of plot to be drawn, same as in \code{\link{plot}}.} +} +\description{ +Add time series lines to an existing xts plot +} +\author{ +Ross Bennett +} \ No newline at end of file Added: pkg/xts/man/points.xts.Rd =================================================================== --- pkg/xts/man/points.xts.Rd (rev 0) +++ pkg/xts/man/points.xts.Rd 2015-01-10 15:40:11 UTC (rev 869) @@ -0,0 +1,26 @@ +\name{points.xts} +\alias{points.xts} +\title{Add time series of points to an existing xts plot} +\usage{ +\method{points}{xts}(x, ..., main = "", on = NA, col = NULL, pch = 0) +} +\arguments{ +\item{x}{an xts object to plot.} + +\item{\dots}{any other passthrough parameters. Not currently used.} + +\item{main}{main title for a new panel if drawn.} + +\item{on}{panel number to draw on. A new panel will be drawn if \code{on=NA}.} + +\item{col}{color palette to use, set by default to rational choices.} + +\item{pch}{the type of plot to be drawn, same as in \code{\link{plot}}.} +} +\description{ +Add time series of points to an existing xts plot +} +\author{ +Ross Bennett +} + From noreply at r-forge.r-project.org Sat Jan 10 17:28:58 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 10 Jan 2015 17:28:58 +0100 (CET) Subject: [Xts-commits] r870 - in pkg/xts: R man Message-ID: <20150110162858.2EC8018779D@r-forge.r-project.org> Author: rossbennett34 Date: 2015-01-10 17:28:57 +0100 (Sat, 10 Jan 2015) New Revision: 870 Modified: pkg/xts/R/plot.R pkg/xts/man/addLegend.Rd pkg/xts/man/plot.xts.Rd Log: refactor addLegend to support drawing legend on given frames of plot Modified: pkg/xts/R/plot.R =================================================================== --- pkg/xts/R/plot.R 2015-01-10 15:40:11 UTC (rev 869) +++ pkg/xts/R/plot.R 2015-01-10 16:28:57 UTC (rev 870) @@ -1051,31 +1051,17 @@ #' @param col fill colors for the legend. If \code{NULL}, #' the colorset of the current plot object data is used. #' @param ncol number of columns for the legend -#' @param \dots any other passthrough parameters. Not currently used. +#' @param \dots any other passthrough parameters to \code{\link{legend}}. #' @author Ross Bennett -addLegend <- function(legend.loc="center", legend.names=NULL, col=NULL, ncol=1, ...){ +addLegend <- function(legend.loc="center", legend.names=NULL, col=NULL, ncol=1, on=1, ...){ lenv <- new.env() - lenv$main <- "" - - plot_object <- current.xts_chob() - ncalls <- length(plot_object$Env$call_list) - plot_object$Env$call_list[[ncalls+1]] <- match.call() - - # add the frame for drawdowns info - plot_object$add_frame(ylim=c(0,1),asp=0.25) - plot_object$next_frame() - text.exp <- expression(text(x=xlim[1], y=0.3, labels=main, - col=1,adj=c(0,0),cex=0.9,offset=0,pos=4)) - plot_object$add(text.exp, env=c(lenv,plot_object$Env), expr=TRUE) - - # add frame for the legend panel - plot_object$add_frame(ylim=c(0,1),asp=0.8,fixed=TRUE) - plot_object$next_frame() - - if(!is.null(legend.loc)){ - yrange <- c(0,1) - nobs <- plot_object$Env$nobs - chob.xlim <- plot_object$Env$xlim + lenv$plot_legend <- function(x, legend.loc, legend.names, col, ncol, on, ...){ + if(is.na(on)){ + yrange <- c(0, 1) + } else { + yrange <- x$Env$ylim[[2*on]] + } + chob.xlim <- x$Env$xlim switch(legend.loc, topleft = { xjust <- 0 @@ -1132,28 +1118,76 @@ ly <- yrange[1] } ) + # this just gets the data of the main plot + # TODO: get the data of frame[on] + if(is.null(ncol)){ + ncol <- NCOL(x$Env$xdata) + } + if(is.null(col)){ + col <- x$Env$theme$col[1:nc] + } + if(is.null(legend.names)){ + legend.names <- x$Env$column_names + } + legend(x=lx, y=ly, legend=legend.names, xjust=xjust, yjust=yjust, + ncol=ncol, col=col, bty="n", ...) } - nc <- NCOL(plot_object$Env$xdata) - lenv$lx <- lx - lenv$ly <- ly - lenv$xjust <- xjust - lenv$yjust <- yjust - if(!is.null(col)){ - lenv$col <- col[1:nc] + + # store the call + plot_object <- current.xts_chob() + ncalls <- length(plot_object$Env$call_list) + plot_object$Env$call_list[[ncalls+1]] <- match.call() + + # if on[1] is NA, then add a new frame for the legend + if(is.na(on[1])){ + # map all passed args (if any) to 'lenv' environment + mapply(function(name,value) { assign(name,value,envir=lenv) }, + names(list(legend.loc=legend.loc, legend.names=legend.names, col=col, ncol=ncol, on=on,...)), + list(legend.loc=legend.loc, legend.names=legend.names, col=col, ncol=ncol, on=on,...)) + exp <- parse(text=gsub("list","plot_legend", + as.expression(substitute(list(x=current.xts_chob(), + legend.loc=legend.loc, + legend.names=legend.names, + col=col, + ncol=ncol, + on=on, + ...)))), + srcfile=NULL) + + # add frame for spacing + plot_object$add_frame(ylim=c(0,1),asp=0.25) + plot_object$next_frame() + text.exp <- expression(text(x=xlim[1], y=0.3, labels=main, + col=1,adj=c(0,0),cex=0.9,offset=0,pos=4)) + plot_object$add(text.exp, env=c(lenv,plot_object$Env), expr=TRUE) + + # add frame for the legend panel + plot_object$add_frame(ylim=c(0,1),asp=0.8,fixed=TRUE) + plot_object$next_frame() + + # add plot_legend expression + plot_object$add(exp,env=c(lenv, plot_object$Env),expr=TRUE,no.update=TRUE) } else { - lenv$col <- plot_object$Env$theme$col[1:nc] + for(i in 1:length(on)) { + ind <- on[i] + no.update <- FALSE + # map all passed args (if any) to 'lenv' environment + mapply(function(name,value) { assign(name,value,envir=lenv) }, + names(list(legend.loc=legend.loc, legend.names=legend.names, col=col, ncol=ncol, on=on,...)), + list(legend.loc=legend.loc, legend.names=legend.names, col=col, ncol=ncol, on=on,...)) + exp <- parse(text=gsub("list","plot_legend", + as.expression(substitute(list(x=current.xts_chob(), + legend.loc=legend.loc, + legend.names=legend.names, + col=col, + ncol=ncol, + on=on, + ...)))), + srcfile=NULL) + plot_object$set_frame(2*on[i]) # this is defaulting to using headers, should it be optionable? + plot_object$add(exp,env=c(lenv, plot_object$Env),expr=TRUE,no.update=no.update) + } } - if(!is.null(legend.names)){ - lenv$names <- legend.names - } else { - lenv$names <- plot_object$Env$column_names - } - lenv$nc <- ncol - # add expression for legend - exp <- expression(legend(x=lx, y=ly, legend=names, xjust=xjust, yjust=yjust, - fill=col, ncol=nc, bty="n")) - - plot_object$add(exp,env=c(lenv, plot_object$Env),expr=TRUE,no.update=TRUE) plot_object } Modified: pkg/xts/man/addLegend.Rd =================================================================== --- pkg/xts/man/addLegend.Rd 2015-01-10 15:40:11 UTC (rev 869) +++ pkg/xts/man/addLegend.Rd 2015-01-10 16:28:57 UTC (rev 870) @@ -1,10 +1,9 @@ -% Generated by roxygen2 (4.0.1): do not edit by hand \name{addLegend} \alias{addLegend} \title{Add Legend} \usage{ addLegend(legend.loc = "center", legend.names = NULL, col = NULL, - ncol = 1, ...) + ncol = 1, on = 1, ...) } \arguments{ \item{legend.loc}{legend.loc places a legend into one of nine locations on @@ -19,7 +18,9 @@ \item{ncol}{number of columns for the legend} -\item{\dots}{any other passthrough parameters. Not currently used.} +\item{on}{panel number to draw on. A new panel will be drawn if \code{on=NA}.} + +\item{\dots}{any other passthrough parameters to \code{\link{legend}}.} } \description{ Add Legend Modified: pkg/xts/man/plot.xts.Rd =================================================================== --- pkg/xts/man/plot.xts.Rd 2015-01-10 15:40:11 UTC (rev 869) +++ pkg/xts/man/plot.xts.Rd 2015-01-10 16:28:57 UTC (rev 870) @@ -1,4 +1,3 @@ -% Generated by roxygen2 (4.0.1): do not edit by hand \name{plot.xts} \alias{plot.xts} \title{Time series Plotting} From noreply at r-forge.r-project.org Wed Jan 14 14:26:34 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 14 Jan 2015 14:26:34 +0100 (CET) Subject: [Xts-commits] r871 - in pkg/xts: R man Message-ID: <20150114132635.044FD187942@r-forge.r-project.org> Author: rossbennett34 Date: 2015-01-14 14:26:34 +0100 (Wed, 14 Jan 2015) New Revision: 871 Removed: pkg/xts/man/lines.xts.Rd pkg/xts/man/points.xts.Rd Modified: pkg/xts/R/plot.R pkg/xts/man/plot.xts.Rd Log: consolidating lines.xts and points.xts into plot.xts.Rd file for consistency with previous documentation added examples to plot.xts man file Modified: pkg/xts/R/plot.R =================================================================== --- pkg/xts/R/plot.R 2015-01-10 16:28:57 UTC (rev 870) +++ pkg/xts/R/plot.R 2015-01-14 13:26:34 UTC (rev 871) @@ -865,8 +865,8 @@ plot_object } -lines.xts <- function(x, ..., main="", on=NA, col=NULL, lty=1, lwd=1, pch=0){ - addSeries(x, ...=..., main=main, on=on, type="l", col=col, lty=lty, lwd=lwd, pch=pch) +lines.xts <- function(x, ..., main="", on=NA, col=NULL, type="l", lty=1, lwd=1, pch=0){ + addSeries(x, ...=..., main=main, on=on, type=type, col=col, lty=lty, lwd=lwd, pch=pch) } Deleted: pkg/xts/man/lines.xts.Rd =================================================================== --- pkg/xts/man/lines.xts.Rd 2015-01-10 16:28:57 UTC (rev 870) +++ pkg/xts/man/lines.xts.Rd 2015-01-14 13:26:34 UTC (rev 871) @@ -1,30 +0,0 @@ -\name{lines.xts} -\alias{lines.xts} -\title{Add time series lines to an existing xts plot} -\usage{ -\method{lines}{xts}(x, ..., main = "", on = NA, col = NULL, lty = 1, - lwd = 1, pch = 0) -} -\arguments{ -\item{x}{an xts object to plot.} - -\item{\dots}{any other passthrough parameters. Not currently used.} - -\item{main}{main title for a new panel if drawn.} - -\item{on}{panel number to draw on. A new panel will be drawn if \code{on=NA}.} - -\item{col}{color palette to use, set by default to rational choices.} - -\item{lty}{set the line type, same as in \code{\link{plot}}.} - -\item{lwd}{set the line width, same as in \code{\link{plot}}.} - -\item{pch}{the type of plot to be drawn, same as in \code{\link{plot}}.} -} -\description{ -Add time series lines to an existing xts plot -} -\author{ -Ross Bennett -} \ No newline at end of file Modified: pkg/xts/man/plot.xts.Rd =================================================================== --- pkg/xts/man/plot.xts.Rd 2015-01-10 16:28:57 UTC (rev 870) +++ pkg/xts/man/plot.xts.Rd 2015-01-14 13:26:34 UTC (rev 871) @@ -1,6 +1,8 @@ \name{plot.xts} \alias{plot.xts} -\title{Time series Plotting} +\alias{lines.xts} +\alias{points.xts} +\title{Plotting xts Objects} \usage{ \method{plot}{xts}(x, y = NULL, ..., subset = "", FUN = NULL, panels = NULL, multi.panel = FALSE, col = 1:12, up.col = "green", @@ -11,13 +13,17 @@ 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) +\method{lines}{xts}(x, ..., main = "", on = NA, col = NULL, type = "l", + lty = 1, lwd = 1, pch = 0) +\method{points}{xts}(x, ..., main = "", on = NA, col = NULL, pch = 0) } \arguments{ \item{x}{xts object} \item{y}{NULL, not used} -\item{\dots}{any passthrough parameters to FUN} +\item{\dots}{any passthrough parameters to FUN for \code{plot} and additional graphical +arguments for \code{lines} and \code{points}} \item{subset}{character vector of length one of the subset range using subsetting as in \code{\link{xts}}} @@ -88,6 +94,10 @@ \item{legend.loc}{places a legend into one of nine locations on the chart: bottomright, bottom, bottomleft, left, topleft, top, topright, right, or center. Default NULL does not draw a legend.} + +\item{pch}{the plotting character to use, same as in \code{\link{par}}.} + +\item{on}{panel number to draw on. A new panel will be drawn if \code{on=NA}.} } \description{ Plotting for xts objects. @@ -96,4 +106,45 @@ \author{ Ross Bennett } +\references{ +based on \code{chart_Series} in the \code{quantmod} package by Jeffrey A. Ryan +} +\examples{ +\dontrun{ +data(sample_matrix) +sample.xts <- as.xts(sample_matrix) +# plot the Close +plot(sample.xts[,"Close"]) + +# plot a subset of the data +plot(sample.xts[,"Close"], subset="2007-04-01/2007-06-31") + +# function to compute simple returns +simple.ret <- function(x, col.name){ + x[,col.name] / lag(x[,col.name]) - 1 +} + +# pass in the simple.ret function and plot the output +plot(sample.xts, FUN=simple.ret, col.name="Close") + +# plot the close and add a panel with the simple returns +plot(sample.xts[,"Close"]) +R <- simple.ret(sample.xts, "Close") +lines(R, type="h") + +# add the 50 period simple moving average to panel 1 of the plot +library(TTR) +lines(SMA(sample.xts[,"Close"], n = 50), on=1, col="blue") + +# add month end points to the chart +points(sample.xts[endpoints(sample.xts[,"Close"], on = "months"), "Close"], + col="red", pch=17, on=1) + +# add legend to panel 1 +addLegend("topright", on=1, + legend.names = c("Close", "SMA(50)"), + lty=c(1, 1), lwd=c(2, 1), + col=c("black", "blue", "red")) +} +} Deleted: pkg/xts/man/points.xts.Rd =================================================================== --- pkg/xts/man/points.xts.Rd 2015-01-10 16:28:57 UTC (rev 870) +++ pkg/xts/man/points.xts.Rd 2015-01-14 13:26:34 UTC (rev 871) @@ -1,26 +0,0 @@ -\name{points.xts} -\alias{points.xts} -\title{Add time series of points to an existing xts plot} -\usage{ -\method{points}{xts}(x, ..., main = "", on = NA, col = NULL, pch = 0) -} -\arguments{ -\item{x}{an xts object to plot.} - -\item{\dots}{any other passthrough parameters. Not currently used.} - -\item{main}{main title for a new panel if drawn.} - -\item{on}{panel number to draw on. A new panel will be drawn if \code{on=NA}.} - -\item{col}{color palette to use, set by default to rational choices.} - -\item{pch}{the type of plot to be drawn, same as in \code{\link{plot}}.} -} -\description{ -Add time series of points to an existing xts plot -} -\author{ -Ross Bennett -} - From noreply at r-forge.r-project.org Sat Jan 24 19:48:47 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 24 Jan 2015 19:48:47 +0100 (CET) Subject: [Xts-commits] r872 - in pkg/xts: R man Message-ID: <20150124184847.AFC16186AB2@r-forge.r-project.org> 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} From noreply at r-forge.r-project.org Sun Jan 25 14:29:48 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 25 Jan 2015 14:29:48 +0100 (CET) Subject: [Xts-commits] r873 - pkg/xts Message-ID: <20150125132948.99971187322@r-forge.r-project.org> Author: rossbennett34 Date: 2015-01-25 14:29:48 +0100 (Sun, 25 Jan 2015) New Revision: 873 Modified: pkg/xts/DESCRIPTION Log: making the Date field a variable and bumping version minor number to match the svn revision number so we have a distinct dev version on R-Forge that differs from the stable CRAN release Modified: pkg/xts/DESCRIPTION =================================================================== --- pkg/xts/DESCRIPTION 2015-01-24 18:48:47 UTC (rev 872) +++ pkg/xts/DESCRIPTION 2015-01-25 13:29:48 UTC (rev 873) @@ -1,8 +1,8 @@ Package: xts Type: Package Title: eXtensible Time Series -Version: 0.9-7 -Date: 2013-06-26 +Version: 0.9.873 +Date: $Date$ Author: Jeffrey A. Ryan, Joshua M. Ulrich Depends: zoo (>= 1.7-10) LinkingTo: zoo From noreply at r-forge.r-project.org Thu Jan 29 18:54:32 2015 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 29 Jan 2015 18:54:32 +0100 (CET) Subject: [Xts-commits] r874 - in pkg/xts: . R Message-ID: <20150129175432.8CA7E187971@r-forge.r-project.org> Author: rossbennett34 Date: 2015-01-29 18:54:32 +0100 (Thu, 29 Jan 2015) New Revision: 874 Modified: pkg/xts/DESCRIPTION pkg/xts/R/plot.R Log: fix bug in addEventLines that clobbered user argument for col Modified: pkg/xts/DESCRIPTION =================================================================== --- pkg/xts/DESCRIPTION 2015-01-25 13:29:48 UTC (rev 873) +++ pkg/xts/DESCRIPTION 2015-01-29 17:54:32 UTC (rev 874) @@ -1,7 +1,7 @@ Package: xts Type: Package Title: eXtensible Time Series -Version: 0.9.873 +Version: 0.9.874 Date: $Date$ Author: Jeffrey A. Ryan, Joshua M. Ulrich Depends: zoo (>= 1.7-10) Modified: pkg/xts/R/plot.R =================================================================== --- pkg/xts/R/plot.R 2015-01-25 13:29:48 UTC (rev 873) +++ pkg/xts/R/plot.R 2015-01-29 17:54:32 UTC (rev 874) @@ -917,12 +917,18 @@ if(!is.null(event.labels)) if(length(event.dates) != length(event.labels)) stop("length of event.dates must match length of event.labels") + if(length(event.dates) > 1){ + if(length(lty) == 1) lty <- rep(lty, length(event.dates)) + if(length(lwd) == 1) lwd <- rep(lwd, length(event.dates)) + if(length(col) == 1) col <- rep(col, length(event.dates)) + } + lenv <- new.env() lenv$main <- main lenv$plot_event_lines <- function(x, event.dates, event.labels, date.format, on, lty, lwd, col, ...){ xdata <- x$Env$xdata xsubset <- x$Env$xsubset - col <- x$Env$theme$col + # col <- x$Env$theme$col if(all(is.na(on))){ # Add x-axis grid lines atbt <- axTicksByTime2(xdata[xsubset])