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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Jan 14 14:26:34 CET 2015


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
-}
-



More information about the Xts-commits mailing list