Welcome to Line Plots. In this video, you will learn how to plot basic line plots, change the axis labels and colors of plots, and plot multiple line plots. Line plots help you visualize time series data. Throughout this lesson, you will see examples of line plots that use the “EUStockMarkets” time series dataset, which comes with the ggplot2 package. To see more details about the data, enter question mark EUStockMarkets. This dataset contains 1860 rows and 4 variables so to display only the first six rows in the dataset, use the head() function. This dataset is an “mts” or multivariate time series object. Because ggplot cannot plot time series objects, you must first convert it to a data frame, and then extract the date information using the time() function. Notice that the dataset now has a “Date” column. Later in this video, you will learn a simpler way to convert the dataset so it can be used more easily with tidyverse. The main function to create line plots is geom_line(). To create a line plot, you must first use the ggplot() function to specify variables for the x and y-axis. In this example with the EuStockMarkets dataset, the x-axis is the “date” and the y axis is “SMI”, which is the daily closing prices for the stock market index SMI (for Switzerland.) Then, to create the line, you add the geom_line() function. By default, the x and y-axis labels will be the name of the variables you specified when creating the plot. However, the variable names are often not descriptive enough. For example, if someone were to glance at this graph, they may not understand what “SMI” means. So, to change the axis labels, you can add the labs() function and specify a new name for the y axis labels. Now, with more descriptive labels, it is clear what this graph is telling us. It is often helpful to see multiple lines on the same plot so you can compare multiple variables over time. To add another line to the plot, you can add another geom_line() function. For example, in this plot there is a line for every stock index. However, there are several drawbacks to using this method. The y axis label and scales (click 2) may not make sense for all the variables. Also, (click 3) you must manually call geom_line() and set the color for every new line. You may have to do a lot of customization to the plot for it to make sense. Also, notice that the y axis in the plot gets labelled with the name of the y variable in the first geom_line() function. Let's look at another way to create a multiple line plot using this same data. If you look at the original EUStockMarkets dataset, you will see that the market stock indexes are arranged by columns instead of rows. This is a common problem that can be solved by tidying the data, so it is aligned in rows instead. This makes it simpler to create multiple line plots. To easily ”tidy” up the time series object, you can use the function tidy, which is included in the “broom” library. room is included in tidyverse so you do not need to install anything, but you may have to load broom. By default, the names of the columns become index, series, and value. You can use rename() to change the column names. Now, you can see that the dataset was transformed to three columns. There is the date column, which was automatically extracted from the time series object (like in the example you saw earlier in the video.) There is the Stock_Index column that reflects the name of each column in the original dataset. Finally, there is the Price column that includes the values in the original dataset. For example, in the original data frame, the first row corresponds to the first four rows in the transformed dataset. With this tidied dataset, it is simple to create a multiple line plot because you do not need to add geom_line() for every new line you want to plot. To create the line plot, set x as the date, y as price, and then set the color equal to the variable you tidied up. In this example, the variable is Stock_Index. All the line colors and the legend are automatically set, so you do not need to manually set them. In this video, you learned that line plots visualize time series data. You also learned to create a line plot by specifying an x- and y-axis using the geom_line() function and then modify the X and Y axis labels and the line colors. Finally, you learned two ways to create multiple line plots.