[R-SIG-Finance] Empty indicator / plot.window: need finite 'ylim' values
Daniel Cegiełka
d@n|e|@ceg|e|k@ @end|ng |rom gm@||@com
Mon Aug 17 23:46:16 CEST 2020
> On 17 Aug 2020, at 22:42, Mike <mike9 using posteo.nl> wrote:
> Like Joshua wrote, indeed, I use chart_Series within a function.
>
>> But your problem is here:
>>
>> sample.xts[subset, 2]
>
> Yes, not the main window is the issue, but the indicator is. So I
> have to ask more specific:
>
> Can I plot a subset of chart and indicator where the indicator's
> subset is completely NA resulting in the indicator's plot region
> being left blank?
>
you can try to force a value for ylim in the quantmod’s chart object:
x <- chart_Series (sample.xts[,1], subset=subset, TA=ta)
> x$Env$ylim
[[1]]
[1] 0 1
attr(,"fixed")
[1] FALSE
[[2]]
[1] 49.88096 50.67835
attr(,"fixed")
[1] FALSE
[[3]]
[1] 0 1
attr(,"fixed")
[1] FALSE
[[4]]
[1] -Inf Inf
attr(,"fixed")
[1] FALSE
e.g.:
> x$Env$ylim[[4]] <- structure(c(0, 1), 'fixed' = FALSE)
>
> x$Env$ylim[[4]]
[1] 0 1
attr(,"fixed")
[1] FALSE
however, it is still overwritten:
> x # or plot(x)
Error in plot.window(c(1, 21), c(NaN, NaN)) : need finite 'ylim' values
In addition: Warning messages:
1: In min(x) : no non-missing arguments to min; returning Inf
2: In max(x) : no non-missing arguments to max; returning -Inf
> x$Env$ylim[[4]]
[1] -Inf Inf
attr(,"fixed")
[1] FALSE
> Mike
>
>
> The new 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', '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))
> }
>
> my_plot_function ()
>
> _______________________________________________
> R-SIG-Finance using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-sig-finance
> -- Subscriber-posting only. If you want to post, subscribe first.
> -- Also note that this is not the r-help list where general R questions should go.
More information about the R-SIG-Finance
mailing list