Get startedGet started for free

Manipulating and visualizing your data

1. Manipulating and visualizing your data

Now that you've practiced converting your data into an xts object, it's time to begin manipulating and exploring your data.

2. Qualities of xts objects

First, you'll want to identify the qualities of your data. One important quality of any time series data is periodicity, or the units of time used to distinguish each observation. Time series data can be measured on any time scale, from observations every century to observations every second. The periodicity() command in xts will identify the time scale and scope of your data.

3. Plotting time series data

Once you understand the periodicity of your data, another useful step is to plot your data over time. The most common methods for plotting time series data are the plot.xts() command and the plot.zoo() command. Both commands use the time index of your xts object as the x-axis by default. This allows you to easily visualize trends over time. Returning to our example from the previous video, we can see that the population in our city appears to be growing over time. But what if you'd like to add a more complex trend to this plot? Not only is population growth positive, it appears to be accelerating.

4. Plotting time series data

Remember that xts objects have many of the qualities of matrix objects, including the ability to handle math operations. To derive more complex values from your time series data, you can simply calculate an additional column. In our city population data, we can calculate annual growth by taking the difference from year to year as a percentage. Plotting this new column of data, we can confirm that population growth is accelerating over time.

5. Let's practice!

Let's practice on our Boston flight data!