Learn R Programming

QuantTools (version 0.5.2)

plot_ts: Plot time series

Description

Plot time series

Usage

plot_ts(dt, type = "auto", col = "auto", lty = par("lty"), lwd = par("lwd"), pch = par("pch"), legend = c("topright", "topleft", "bottomright", "bottomleft", "n"), last_values = TRUE, main = "", ylim = "auto", xlim = "auto", time_range = "auto", resolution = "auto", log = par("ylog"), mar = par("mar"), xaxt = par("xaxt"), add = par("new"))
t_to_x(t)

Arguments

dt
data.table with date/time index represented by first column. If OHLC detected then only candles plotted. Use lines for the rest of data
type
type vector or single value. Same as in plot but 'candle' supports. Default is 'l'. 'h' triggers adding zero to plot range
col
color vector or single value. Default is 'auto' so colors generated automatically
lty, lwd, pch
parameters vectors or single values. Same as in plot
legend
position of plot legend. Supported positions are 'topright','topleft','bottomright','bottomleft' or 'n' to hide legend
last_values
whether to add last values marks to the right of the plot. If vector specified marks added only for columns specified in vector
main
title of the plot. Default is ''
ylim
y range of data to plot
xlim
x range of data to plot
time_range
time range in format 'HH:MM:SS/HH:MM:SS'
resolution
frequency of time marks on time axis. Supported resolutions are 'auto','minute','hour','day','month','year','years'. Default is 'auto'
log
should y axis be in logarithmic scale?
mar
same as in par
xaxt
same as in par
add
add to existing plot?
t
date/time vector to be converted to plot x coordinates

Details

Plots time series each represented by columns of times_series on single plot. As for OHLC series, only one can be plotted and should be passed as times_series with 4 columns 'open','high','low','close'.

See Also

Other graphical functions: add_last_values, add_legend, distinct_colors, empty_plot, hist_dt, lines_ohlc, lines_stacked_hist, multi_heatmap, plot_table

Examples

Run this code

time_series <- get_finam_data( 'SBER', '2014-01-10', '2014-08-13', period = '10min' )

plot_ts( time_series[ time %bw% '2014-08-13', list( time, open, high, low, close ) ] )
plot_ts( time_series[ time %bw% '2014-08-13', list( time, volume = volume / 1e6 )  ] , type = 'h' )
plot_ts( time_series[ time %bw% '2014-08', list( time, close ) ] )
plot_ts( time_series[ , list( time, close ) ] )


time_series <- get_finam_data( 'SBER', '2014-01-10', '2014-08-13', period = '10min' )

mar = par( 'mar' )
par( mar = c( 0, 4, 0, 4 ), xaxt = 'n' )
layout ( matrix( 1:(3 + 2) ), heights = c( 1, 4, 2, 2, 1 ) )
  empty_plot()
  plot_ts( time_series[ , list( time, open, high, low, close ) ] )
  plot_ts( time_series[ , list( time, close ) ] )
  par( xaxt = 's' )
  plot_ts( time_series[ , list( time, vol = vol / 1e6 ) ], type = 'h' )
  empty_plot()
par( mar = mar )


Run the code above in your browser using DataLab