Plotting Time Series in R

While we can explore time series data using commands such as print()head()tail(), etc in R, it can be very helpful to plot the time series data as a line chart and explore it visually.

In the following examples, we plot the Microsoft stock data and the quarterly GDP data in two different plots using the plot() function in R. You can alternatively also use ts.plot() function.

> plot(msft_ts,xlab="Day",ylab="Closing price", main="MSFT Closing Stock Prices")

> plot(GDP_data,xlab="Time",ylab="GDP", main="GDP Data",type="b")

Both the series show an upward trend over time. The trend for the MSFT stock is not very clear during the first half of the year, however during the send half, it is a clear uptrend. The GDP graph on hand, has an uptrend since the beginning.

Related Downloads

Data Science in Finance: 9-Book Bundle

Data Science in Finance Book Bundle

Master R and Python for financial data science with our comprehensive bundle of 9 ebooks.

What's Included:

  • Getting Started with R
  • R Programming for Data Science
  • Data Visualization with R
  • Financial Time Series Analysis with R
  • Quantitative Trading Strategies with R
  • Derivatives with R
  • Credit Risk Modelling With R
  • Python for Data Science
  • Machine Learning in Finance using Python

Each book includes PDFs, explanations, instructions, data files, and R code for all examples.

Get the Bundle for $29 (Regular $57)
JOIN 30,000 DATA PROFESSIONALS

Free Guides - Getting Started with R and Python

Enter your name and email address below and we will email you the guides for R programming and Python.

Data Science in Finance: 9-Book Bundle

Data Science in Finance Book Bundle

Master R and Python for financial data science with our comprehensive bundle of 9 ebooks.

What's Included:

  • Getting Started with R
  • R Programming for Data Science
  • Data Visualization with R
  • Financial Time Series Analysis with R
  • Quantitative Trading Strategies with R
  • Derivatives with R
  • Credit Risk Modelling With R
  • Python for Data Science
  • Machine Learning in Finance using Python

Each book comes with PDFs, detailed explanations, step-by-step instructions, data files, and complete downloadable R code for all examples.