joshuaulrich / quantmod

Quantitative Financial Modelling Framework
http://www.quantmod.com/
GNU General Public License v3.0
809 stars 223 forks source link

add support for log scale axis in chart_Series #303

Open ethanbsmith opened 4 years ago

ethanbsmith commented 4 years ago

Description

Neither of these approaches produce a log scaled y axis

chart_Series(x, log.scale=TRUE)  # like in chartSeries()
chart_Series(x, log="y")         # like in plot.default()

This problem was also identified at : https://stackoverflow.com/questions/25261388/does-chart-series-work-with-logarithmic-axis

Expected behavior

some parameter that will allow at least the y axis to be log scaled. ideally this would also work TA panels

Session Info

> sessionInfo()
R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252 LC_NUMERIC=C                           LC_TIME=English_United States.1252    

attached base packages:
[1] parallel  stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] rio_0.5.16        rvest_0.3.4       xml2_1.2.2        data.table_1.12.2 curl_4.2          quantmod_0.4-15   TTR_0.23-5        xts_0.11-2        zoo_1.8-6         RODBC_1.3-16      doParallel_1.0.15 iterators_1.0.12 
[13] foreach_1.4.7     plotrix_3.7-6     checkpoint_0.4.7 

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2       magrittr_1.5     hms_0.5.1        lattice_0.20-38  R6_2.4.0         rlang_0.4.0      httr_1.4.1       tools_3.6.3      grid_3.6.3       readxl_1.3.1     tibble_2.1.3     crayon_1.3.4     zip_2.0.4       
[14] vctrs_0.2.0      codetools_0.2-16 zeallot_0.1.0    haven_2.1.1      openxlsx_4.1.0.1 cellranger_1.1.0 pillar_1.4.2     compiler_3.6.3   backports_1.1.4  forcats_0.4.0    foreign_0.8-75   pkgconfig_2.0.3 
> 
ethanbsmith commented 4 years ago

so i looked into this a bit today. want to log some notes here for reference:

Findings:

so, there are a few things that need to be sorted out:

  1. how do we want pars to be passed in to chart_Series? through ... to make it like plot.xts, or through the explicit existing pars argument?
  2. if some pars are required (like cex and mar), should they be handled through some other defaulting mechanism so that they can be merged with user supplied pars like log
  3. how should pars be passed down teh function chain? a. maybe the xtscode can be leveraged to assemble an expression that can be placed into the replot object instead of explicit slots for cex and mar. Or b. possibly placing the whole par including user supplied values into the replot
ethanbsmith commented 2 years ago

while this could be handled through a pars parameter, the same could have been done for the original chartSeries. i think adding a log.scale parameter to the chart_Series function signature, that gets passed through to plot.xts is the better design.

ethanbsmith commented 1 year ago

dependent on https://github.com/joshuaulrich/xts/issues/103