how to customize x axis in xts plot

1.5k views Asked by At

Following from this topic How do I set width of candles in candle chart using plot.xts? , I have noticed how plot.xts creates such fantastic candlestick plot. However when I tried the codes from that post I cannot get the x axis right. I tried

start <- as.Date('2007-01-03');end<-as.Date('2007-12-31')
from.dat <- start;to.dat <- end
getSymbols("C", src="yahoo", from = from.dat, to = to.dat)
candlecolors <- ifelse(C[,'C.Close'] < C[,'C.Open'], 'RED', 'GREEN')
plot.xts(C, type='candles',width=70000, candle.col=candlecolors,     bar.col='BLACK',cex.axis=1.5,main='Candlestick plot of Citigroup (2007)',cex.main=2)

The x axis isn't as I desired. I need something similar to the coloured plot from this post How do I set width of candles in candle chart using plot.xts?

Sorry I haven't got enough reputation to post images. Any help is appreciated.

Regards,

Long

1

There are 1 answers

0
shadowtalker On

The plotting parameter xaxt can be passed to plot.xts(). So the first thing you can do is add the argument xaxt="n" to your plot.xts() call. This will tell R not to automatically draw an axis.

You can then call axis() multiple times, once for each color of tick mark. Read up on the documentation for that function, it's pretty straightforward. If you're stuck, here's a short thread from the R-help archive with a solution: http://r.789695.n4.nabble.com/axis-tick-colors-only-one-value-allowed-td4188284.html.

On the other hand there might be a better solution somewhere in the xts package.