Hi Mike, Try this: plot (chart_Series (sample.xts[,1], subset=subset, TA=ta), type="n",ylim=c(minimum,maximum))
where minimum and maximum are the extremes of the plot if there were any valid values. Jim On Fri, Aug 21, 2020 at 6:32 PM Mike <mi...@posteo.nl> wrote: > > Dear R users, > > I have already asked this in r-sig-finance (not getting a solution) > but it seems to be plot-related anyway. > > I like to plot several financial charts to files with an identical > layout according to "indicators" so the charts can be browsed > quickly. > > quantmod::chart_Series is a function to plot a financially-related > chart in the upper part and zero or more indicators below. Normally > these indicators would be assigned defined values at least in some > part of the subset/window to be plotted, which is fine for plot. But > if all observations are NA chart_Series throws > > Error in plot.window(c(1, 31), c(NaN, NaN)) : need finite 'ylim' values > > While this outcome for plot/plot.window may be intended for most > applications it is undesirable here. Getting a blank subwindow here is > intended if the indicator is completely NA (at least in the subset to > be plotted). > > This post > https://stat.ethz.ch/pipermail/r-sig-finance/2020q3/015000.html > suggests to generate the plot object with chart_Series and then to > explicitly set x$Env$ylim[[4]] before plotting - without success. > > Can I tell plot/plot.window to ignore such errors and simply generate > an empty region instead? > > Thanks > Mike > > > My minimal reproducible: > > library(quantmod) > > my_plot_function <- function () { > data (sample_matrix) > sample.xts <- as.xts (sample_matrix[1:50,'Close'], dateFormat="POSIXct") > sample.xts <- cbind (sample.xts, NA) > sample.xts[50,2] <- 0 > colnames (sample.xts) <- c('Close', 'Indicator') > > # Indicator > 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)) > } > > my_plot_function () > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.