Introduction to PloTA library in the Systematic Investor Toolbox

[This article was first published on Systematic Investor » R, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

PloTA ( plot + ta ) library in the Systematic Investor Toolbox is a simple plot interface to charting Time Series and Technical Analysis plots. I created it as an alternative to charting functionality in quantmod package. It is designed to mimic default plot interface and works with xts objects. PloTA implements following methods:

  • plota – main plot method
  • plota2Y – add second Y axis to existing plot
  • plota.lines – plot lines
  • plota.candle – plot Candle
  • plota.ohlc – plot Open/High/Low/Close
  • plota.hl – plot High/Low
  • plota.volume – plot Volume
  • plota.scale.volume – scale Volume
  • plota.grid – add grid
  • plota.legend – plot legend
  • plota.layout – specify plot layout
  • – color theme
  • – color theme
  • – color theme

To start using PloTA, let’s first load Systematic Investor Toolbox:

 # load Systematic Investor Toolbox
source(gzcon(url('', 'rb')))

Next let’s load quantmod package and download price history for SPY and IBM:


# download sample data from Yahoo
data.spy = getSymbols('SPY', from = '1980-01-01', auto.assign = FALSE) = getSymbols('IBM', from = '1980-01-01', auto.assign = FALSE)

Next I will show a few simple uses of PloTA library.

To create a simple chart of SPY:

y = data.spy['2011:01:01::2011:02:01']
highlight = which(Cl(y) < 127)

png(filename = 'plot1.png', width = 500, height = 500, units = 'px', pointsize = 12, bg = 'white')

plota(y, type = 'candle', main = 'SPY', plotX = F, x.highlight = highlight)
	y = plota.scale.volume(y)
plota(y, type = 'volume', x.highlight = highlight)

To create a simple chart of SPY with RSI and Legend:

y = data.spy['2010:01:01::2011:02:01']

plota(y, type = 'candle', plotX = F)
	plota.legend('SPY', 'blue', y)

y = plota.scale.volume(y)
plota(y, type = 'volume', plotX = F)
	plota.legend('Volume', 'blue', Vo(y))

rsi = RSI(Cl(y),2)
plota(rsi, type = 'l', y.highlight = c(c(Inf,80),c(20,-Inf)))
	abline(h = 20, col = 'red')
	abline(h = 80, col = 'red')
	plota.legend('RSI(2)', 'black', rsi)

To create a chart with second Y axis:

y = data.spy['2010:01:01::2011:02:01']

# to plot second Y axis, free some space on left side
# e.g. set LeftMargin=3
plota(y, type = 'ohlc', LeftMargin=3)

y0 = y;
y =['2010:10:15::2011:02:01']
plota2Y(y, ylim = range(OHLC(y)),las=1, col='red', col.axis = 'red')
	plota.ohlc(y, col = 'red')
	plota.legend('SPY(rhs),IBM(lhs)', 'blue,red', list(y0,y))

To plot daily and monthly on the same plot:

y = data.spy['2010:01:01::2011:02:01']

plota(y, type = 'candle')
	y1 = to.monthly(y)
		index(y1) = as.Date(index(y1))
	plota.ohlc(y1, col = 'pink')
	plota.legend('Daily,Monthly', 'red,pink')

To plot daily, weekly and monthly:

y = data.spy['2010:01:01::2011']

plota(y, type = 'candle', plotX = F)
	plota.legend('Daily', 'blue', y)

plota(y, ylim = range(OHLC(y)), plotX = F)
	y1 = to.weekly(y)
		index(y1) = as.Date(index(y1))
	plota.legend('Weekly', 'blue', y1)

plota(y, ylim = range(OHLC(y)))
	y1 = to.monthly(y)
		index(y1) = as.Date(index(y1))
	plota.legend('Monthly', 'blue', y1)

I will show more examples of PloTA in the future posts.

To leave a comment for the author, please follow the link and comment on their blog: Systematic Investor » R. offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)