Arnaud Amsellem covers XTS objects in R, the standard structure for time-series data with a timestamp index. He shows how to plot XTS series using plot() and customize them with arguments like col for line color, lwd for line width, and main for title. A practical tip: use lines() to change colors without re-plotting.
Chapters
Welcome to Visualizing Time Series Data in R. My name is Arno Mselem and I'll be your instructor for this course. There is a fundamental difference between general plot and a time series plot. In a time series plot, each value is associated to a timestamp where in a general plot there is no time index, there is no orderings. In the data. In R, there is a special class of object to handle time, the XTS object. XTS stands for Extensible Time Series, and this is a class of data that contains an array of value comprising data, often in a matrix form, and an index attribute. To provide information about the data's ordering, the index attribute must be a true time object, date, posix, time, time, date, cron, and so on. Once you have a time series, the obvious question is how to visualize it. In R, the general plot function is plot, but for plotting time series, plot XTS is used instead. One useful trick to remember is that when the underlying object is a time series object, then plot XTS can be abbreviated and plot can be used instead. Let's look at an example. MYTS is a time series that you can plot using plots. You can obviously draw a simple chart, but should you want to make it more readable or add specific information to tailor it. The plot function offers many arguments, probably too many to remember them all, but there are a few that need to be mastered in order to efficiently use R. Once you have drawn myts, the color of the line can be changed with the COL argument. There is a small trick here in order to change the line color without using the plot again, you can use the function lines using COL red to overplot the black line. We will see more about this function in the next chapter. The line thickness can also be adjusted with the LWD argument, and a title can be added with the main argument. You can even add a subtitle with the sub argument. There are many more arguments that can be used. I invite you to have a closer look at our documentation to find out more. Let's test your knowledge with a quick quiz.