Convert quantmod::chart_Series
to interactive d3fc htmlwidget chart.
1 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | ## Not run:
# translate quantmod::chart_Series to d3fc
library(quantmod)
library(d3r)
library(rd3fc)
sp500 <- getSymbols("^GSPC", auto.assign=FALSE)
sp500w <- to.weekly(sp500)
cs <- chart_Series(sp500w)
# live interactive version
# might not show up in RStudio
chartseries(cs)
# examine the chart_Series environment to replicate each
# of the pieces
#listviewer::jsonedit(
# jsonlite::toJSON(as.list(cs$Env), force=TRUE, auto_unbox=TRUE)
#)
# data
cs$Env$xdata
# x axis
# bottom ticks
index(cs$Env$xdata[cs$Env$axt,])
# bottom major ticks
index(cs$Env$xdata[cs$Env$atbt,])
# top ticks and ?location?
cs$Env$axis_ticks(cs$Env$xdata)
# limits
index(cs$Env$xdata[cs$Env$xlim,])
# y axis
# ticks
cs$Env$alabels
# limits
cs$Env$ylim[[2]]
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.