lastobs in rtsplot.legend takes the open instead of close value

Issue #4 closed
Former user created an issue

When plotting a candle chart with rtsplot and adding the legend, the lastobs option shows the open instead of the close as it should be when using a candle chart.

reproducible example:

library(quantmod)
library(rtsplot)
ADM <- getSymbols("ADM", auto.assign = FALSE, from = "2018-01-01", to = "2018-07-01")
rtsplot(ADM, type = "candle")
rtsplot.legend(labels = "ADM", 
               lastobs = ADM)

The reason is that when lastobs is not null unclass(mlast(lastobs))[1] takes the value from the first column instead of the 4th column (close). This is in most plotting cases the correct behaviour, but not in the case of candle (or ohlc) plots.

A workaround is of course specifying lastobs = ADM$ADM.Close, but it would be nice if it was picked up correctly. It avoids confusing differences when comparing with other plot functions like chartSeries.

Comments (2)

  1. rtsvizteam repo owner

    Thank you for reporting the issue and providing the reproducible example. I committed the fix: rtsplot.legend - if last observation is provided, use Close if available; otherwise use first column.

    If you want to use another field for last observation, quantmod package provides number of shortcut functions: Cl, Op, Hi, Lo, Vo, Ad. For example, to use Low as last observation:

    rtsplot.legend(labels = "ADM", lastobs = Lo(ADM))
    
  2. Log in to comment