Plot stock time series with R

Hi all,

I would like to plot the time series corresponding to some stocks. I can see their performance from the Stocks app on my iPhone, but I would like to plot/analyze them in R. Are there specific packages which can help me? To give some context: I'm quite familiar with ggplot2, tidyr and dplyr, and generally with statistical analysis for cross-sectional data. I don't have a lot of experience with time series data, and with connecting to remote data sources through R (my REST API experience is all in Python).

For dealing with time series I like to use tibbletime and the new tsibble they both have pretty much the same functions but the former came up first so I'm more familiar with it.

1 Like

Do they support connection to remote data sources? I'm especially looking to some package which can stream stock performance as easily as the Stocks app on my phone.

They are basically just for doing data wrangling and cleaning with time series, you would need a separate package to fetch the remote data, if the source is a database dbplyr would play nice with tsibble since they are both part of the tidyverse, if the source is an API then take a look to httr package.
Also, I think that for easing real time data acquisition and to make it more similar to your phone app, you would have to develop a shiny app.

1 Like

Also, I think that for easing real time data acquisition and to make it more similar to your phone app, you would have to develop a shiny app.

Learning Shiny is on my to-do list, but I'd rather solve one problem at a time. First I learn how to query the data and build the plots in a R Studio, then I'll think about deploying a web app.

To get started, here is an example use of the quantmod package.

library(quantmod)
StartDate <- "2000-01-01"
ApplePrices <- getSymbols.yahoo('AAPL', 
                                 from = StartDate, 
                                 auto.assign=FALSE)
tail(ApplePrices)
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.