Reputation: 5807
I'll try to define my companies colors and fonts etc to all the plots we're doing. So first question: How can I store them without overwriting the "normal" par settings? I mean can I store all in a "par-Container" and give them to each plot etc?
Ok here I defined the Colors:
GRAPH_BLUE<-rgb(43/255, 71/255,153/255)
GRAPH_ORANGE<-rgb(243/255, 112/255, 33/255)
GRAPH_BACKGROUND<-rgb(180/255, 226/255, 244/255)
If I do plot(something, col=GRAPH_BLUE)
I get the error:
Error in axis(1, at = xycoords$x, labels = FALSE, col = "#BBBBBB", ...) :
formal argument "col" matched by multiple actual arguments
If I do par(col=GRAPH_BLUE)
and plot(something)
it works exactly as I want. Why is that? What would I need to change that it works in the first line of code? As I understand it throws the error since there are multiple settings starting with col
and with plot(something, col=GRAPH_BLUE)
I overwrite all of them and that's why the axis isn't visible. But is there a special col setting for just the color line of the chart?
EDIT: Ok here's a reproducible example:
getSymbols('SPY', from='1998-01-01', to='2011-07-31', adjust=T)
GRAPH_BLUE<-rgb(43/255, 71/255,153/255)
GRAPH_ORANGE<-rgb(243/255, 112/255, 33/255)
GRAPH_BACKGROUND<-rgb(180/255, 226/255, 244/255)
par(col=GRAPH_BLUE)
plot.xts(SPY) #works great
plot.xts(SPY, col=GRAPH_ORANGE) #not really since all axes are missing
And the first question is if I could store all these Settings not directly in par()
but in another variable which I pass to the plot function?
Upvotes: 4
Views: 6475
Reputation: 121568
No there isn't a special col setting for just the color line of the chart. You should use par
or modify the code source of the function and add it like the case of bar.col
or candle.col
. I don't know why they do it for types bar and candle and not for lines? I guess to not have a lot of parameters...
Note the you can save the old parameters of par
every time you change it.
op <- par(col=GRAPH_BLUE)
... ## some plot job
par(op) ## retsore it
It easy also to hack the function and add a new col parameters for lines. Only few lines to change in the function:
plot.xts.col <- function (old.parameters,lines.col='green', ...) {
.....
## you change this line to add the paremeter explicitly
plot(xycoords$x, xycoords$y, type = type, axes = FALSE,
ann = FALSE,col=lines.col, ...)
## and the last line since .xtsEnv is an internal object
assign(".plot.xts", recordPlot(), xts:::.xtsEnv)
}
Upvotes: 3