[R-SIG-Finance] problem with plot.xts

Joshua Ulrich josh.m.ulrich at gmail.com
Fri Nov 11 08:31:22 CET 2011


Hi Eric,

On Thu, Nov 10, 2011 at 9:38 PM, Eric Thungstom
<eric.thungstrom at gmail.com> wrote:
> Please help. I'm getting an error in the plot statement. I've been told
> it's due to plot.xts. and I should ask the package maintainer to send a
> patch. My code is as follows:
>
> require(quantmod)
> require(rdatamarket)
> #rm(list=ls())
> g <-dmlist("
> http://datamarket.com/data/set/1jz5/st-louis-financial-stress-index#display=line&ds=1jz5
> ")
> g$Date <-as.Date(g[,1], "%Y-%m-%d")
> h <-as.xts(g, order.by=g[,1])
> j <-h[,2]
> s <-getSymbols('^GSPC', from="1990-01-01", to=Sys.Date())
> s <-to.weekly(GSPC)
> s <-s[,6]
> x <-na.omit(merge(s,j)) ; names(x) <-c("sp","stress")
> print(head(x))
> par(mfrow=c(2,1))
> plot(x[,1]/400, ylim=c(-1,5), col="blue")
> lines(x[,2], col="red")
> ccf(drop(x[,1]), drop(x[,2]))
>
Thank you for providing a reproducible example.  Next time though, a
_minimal_ example would be better:
library(xts)
data(sample_matrix)
plot(as.xts(sample_matrix[,1]), col="blue")

>
> The error is :
>
> plot(x[,1]/400, ylim=c(-1,5), col="blue")
> Error in axis(1, at = xycoords$x, labels = FALSE, col = "#BBBBBB", ...) :
>  formal argument "col" matched by multiple actual arguments
>
> I tried traceback() but I think it's just telling me there is a problem
> with argument col
>
> traceback()
>
> 3: axis(1, at = xycoords$x, labels = FALSE, col = "#BBBBBB", ...)
> 2: plot.xts(x[, 1]/400, ylim = c(-1, 5), col = "blue")
> 1: plot(x[, 1]/400, ylim = c(-1, 5), col = "blue")
>
traceback() tells you the calls that lead up to the error.  You need
to look at the source code to understand what's going on.

> This code worked in the past without problem. But I upgraded my packages
> and rstudio to the latest version and now I have this error. I tried
> install.packages("xts"). That went fine but didn't fix the error.
>
This changed in xts about 6 months ago.  The error is caused by '...'
being passed to the axis() commands (that already specify a "col"
argument) inside of plot.xts().

> What can I do to resolve this ?
>
Here are a couple work-arounds you can use:
# specify col in a separate call to lines()
plot(as.xts(sample_matrix[,1])); lines(as.xts(sample_matrix[,1]),col="blue")
# or don't draw the minor tick marks
plot(as.xts(sample_matrix[,1]), minor.ticks=FALSE, col="blue")

Best,
--
Joshua Ulrich  |  FOSS Trading: www.fosstrading.com



More information about the R-SIG-Finance mailing list