[R-SIG-Finance] Empty indicator / plot.window: need finite 'ylim' values
Mike
m|ke9 @end|ng |rom po@teo@n|
Mon Aug 17 04:07:10 CEST 2020
I like to plot several charts to files with an identical layout
according to indicators so the charts can be browsed quickly. It is
normal for the indicators in some charts to be completely NA at least
in the range to be plotted. Generating those charts throws
Error in plot.window(c(1, 31), c(NaN, NaN)) : need finite 'ylim' values
To substitute NA by 0, -1 or similar is no option since these are
legal values.
Can I tell R to ignore such errors and simply generate an empty
region instead?
Mike
Minimal reproducible example:
library(quantmod)
data (sample_matrix)
sample.xts <- as.xts (sample_matrix[1:50,'Close'], dateFormat="POSIXct")
sample.xts <- cbind (sample.xts, NA)
sample.xts['2007-02-05::',2] <- 0
sample.xts['2007-02-11',2] <- 1
colnames (sample.xts) <- c('Close', 'Stops')
ta <- list ("add_TA(sample.xts[,2])")
# In the range to be plotted ta is completely NA
subset <- '2007-01-10::2007-01-30'
plot (chart_Series (sample.xts[,1], subset=subset, TA=ta))
More information about the R-SIG-Finance
mailing list