Book Image

Mastering Data analysis with R

By : Gergely Daróczi
Book Image

Mastering Data analysis with R

By: Gergely Daróczi

Overview of this book

Table of Contents (19 chapters)
Mastering Data Analysis with R
Credits
www.PacktPub.com
Preface

Visualizing time-series


This is in a very familiar data structure: 365 rows for each day in 2011 and five columns to store the four metrics for the dates stored in the first variable. Let's transform that to a time-series object and plot it right away:

> plot(ts(daily))

It was easy, right? We have just plotted several independent time-series on a line chart. But what's shown on the first plot? The x axis is indexed from 1 to 365 because ts did not automatically identify that the first column stores our dates. On the other hand, we find the date transformed to timestamps on the y axis. Shouldn't the points form a linear line?

This is one of the beauties of data visualization: a simple plot revealed a major issue with our data. It seems we have to sort the data by date:

> setorder(daily, date)
> plot(ts(daily))

Much better! Now that the values are in the right order, we can focus on the actual time-series data one by one at a time. First let's see how the number of flights looked from...