From 90a419ca40464c7dc0ea2244c13a601846df09db Mon Sep 17 00:00:00 2001 From: Eric Hung Date: Wed, 10 Aug 2016 16:18:05 +0800 Subject: [PATCH] Refactor add_TA to use y_grid_lines instead of custom function The original custom grid_lines function is very similar to y_grid_lines in replot_xts object but the latter restricts the output values to the upper limit and lower limit. About two intervals will be dropped so the labels of prior chart will not be blocked. --- R/chart_Series.R | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/R/chart_Series.R b/R/chart_Series.R index e4afd14c..0a603035 100644 --- a/R/chart_Series.R +++ b/R/chart_Series.R @@ -522,10 +522,8 @@ add_TA <- function(x, order=NULL, on=NA, legend="auto", plot_object$add_frame(ylim=range(na.omit(xdata)),asp=1) # need to have a value set for ylim plot_object$next_frame() - # add grid lines, using custom function for MACD gridlines - lenv$grid_lines <- function(xdata,xsubset) { - pretty(xdata[xsubset]) - } + # add grid lines, using y_grid_lines function from replot_xts object + lenv$grid_lines <- plot_object$Env$y_grid_lines exp <- c(expression(segments(1,grid_lines(xdata,xsubset),NROW(xdata[xsubset]),grid_lines(xdata,xsubset), col=theme$grid)), exp, # NOTE 'exp' was defined earlier to be plot_macd # add axis labels/boxes