#' Plot Index Price
#'
#' Plots an interactive time series plot of the index fund(s) adjusted closing
#' price.
#'
#' @param data A sparse data frame of weekly performance
#' @param scale Uses a log transformation to scale price
#'
#' @import magrittr
#'
#' @export
plot_index_price <- function(data, scale=FALSE) {
# Define color palette
colors <- c("#dc1018", "#12355b", "#3c91e6", "#9fd356", "ffb86f")
# Convert data frame to xts
if (scale) data %<>% dplyr::mutate_if(is.numeric, log)
xtsdata <- xts::xts(data, order.by = data$date)
xtsdata$date <- NULL
# Graph dygraph
xtsdata %>% dygraphs::dygraph(
main = paste("Weekly Adjusted Closing Price,", min(data$date), "to", max(data$date)),
ylab = ifelse(scale, "Log Adjusted Closing Price", "Adjusted Closing Price ($)")
) %>%
dygraphs::dyHighlight(highlightSeriesOpts = list(strokeWidth = 3)) %>%
dygraphs::dyRangeSelector() %>%
dygraphs::dyOptions(colors = colors)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.