class: center, middle, inverse, title-slide # Interactive visualization of multiple time series with plotly ### Carson Sievert ### Slides:
https://bit.ly/r-finance
Twitter:
@cpsievert
GitHub:
@cpsievert
Email:
cpsievert1@gmail.com
Web:
http://cpsievert.github.io/
--- ### plotly ❤️'s time series ```r library(quantmod) getSymbols("AAPL", src = 'yahoo') d <- data.frame(date = index(AAPL), coredata(AAPL)) p1 <- plot_ly(x = d$date, y = d$AAPL.Volume, mode = "lines", name = "volume") p2 <- plot_ly(x = d$date, y = d$AAPL.Adjusted, mode = "lines", name = "adjusted") subplot(p1, p2, nrows = 2, shareX = TRUE) ```
--- ```r rangeslider( subplot(p1, p2, nrows = 2, shareX = TRUE) ) ```
--- ### Have lots of data? Use WebGL! ```r toWebGL( subplot(p1, p2, nrows = 2, shareX = TRUE) ) ```
--- ### Candlestick charts! ```r plot_ly( d, x = ~date, open = ~AAPL.Open, close = ~AAPL.Close, high = ~AAPL.High, low = ~AAPL.Low, type = "candlestick" ) ```
--- ### Small multiples via ggplot2 ```r tx <- subset(txhousing, city %in% c("Galveston", "Midland", "Odessa", "South Padre Island")) p <- ggplot(tx, aes(month, median)) + * geom_line(aes(group = year)) + facet_wrap(~city, ncol = 2) ggplotly(p, tooltip = "year") ```
--- ### Animate via frame aesthetic ```r tx <- subset(txhousing, city %in% c("Galveston", "Midland", "Odessa", "South Padre Island")) p <- ggplot(tx, aes(month, median)) + * geom_line(aes(group = year), alpha = 0.2) + * geom_line(aes(frame = year), color = "red") + facet_wrap(~city, ncol = 2) ggplotly(p, tooltip = "year") ```
--- ### Linked 'brushing' in small multiples ```r sd <- crosstalk::SharedData$new(tx, ~year) p <- ggplot(sd, aes(month, median)) + geom_line(aes(group = year)) + facet_wrap(~city, ncol = 2) highlight(ggplotly(p), persistent = TRUE, dynamic = TRUE, selectize = TRUE) ```
--- class: bottom background-image: url(bcviz.gif) background-size: contain #### https://github.com/cpsievert/bcviz --- background-image: url(plotly.svg) background-size: 100px background-position: 90% 8% class: center, middle, inverse # Thanks! #### Want to sponsor/consult plotly? https://plot.ly/products/consulting-and-oem/ #### Contact me directly Twitter: [@cpsievert](https://twitter.com/cpsievert) <br /> GitHub: [@cpsievert](https://github.com/cpsievert) <br /> Email: <cpsievert1@gmail.com> <br /> Web: <http://cpsievert.github.io/> #### Learn more https://plot.ly/r/ <br /> https://github.com/ropensci/plotly <br /> https://cpsievert.github.io/plotly_book/ <br /> https://cpsievert.github.io/talks/