plotting xts objects - passsing values for lwd and col parameters creating errors

家住魔仙堡 提交于 2019-12-22 10:49:37

问题


Whenever I try to plot my xts object with values passed for parameter col and lwd, it returns an error saying that the parameter col (and then lwd if I comment out col) matched multiple values. Here is what the function looks like -

data is an xts object

plot(data, lwd=2, col="red")

Installing xtsExtra seems to solve the problem, but I don't understand why.


回答1:


xts:::plot.xts specifies several parameters when constructing the axes (col, lwd, las, and mgp), but it also passes ... to the axis call. For example:

axis(1, at = xycoords$x, labels = FALSE, col = "#BBBBBB", ...)

col is already specified, so if you specify it also, it gets passed to axis via ... and now there are two col arguments specified to the axis call.

This isn't a problem with xtsExtra:::plot.xts because those parameters are removed from ... before ... is passed to the axis call.




回答2:


My solution to this to pass type='n' and then call lines:

require(quantmod)
getSymbols('CPIAUCSL',src='FRED')
xts::plot.xts(CPIAUCSL, type='n')
lines(CPIAUCSL, lwd=3, col='darkgoldenrod')

This does not require the xtsExtra package, which makes other changes to the plot and is (maybe) not being actively maintained. (At least it doesn't install via the package manager, today, on R 3.1.1.)



来源:https://stackoverflow.com/questions/16473411/plotting-xts-objects-passsing-values-for-lwd-and-col-parameters-creating-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!