Line Plots
Learn how to generate line plots and change their style.
We'll cover the following...
Features
A line plot is a type of visualization used to display changes in data over time. It consists of a series of data points that are connected by straight lines. We can show trends, highlight anomalies, compare multiple data series, and predict the trends with line charts. We use line plots in various fields like finance, economics, and the natural and social sciences. They are especially useful in visualizing time series data.
Line chart with plot()
The plot()
function is the built-in function for data visualization. It is capable of generating charts in various styles. To generate a line plot, we configure the function using the type = "l"
argument.
It takes at least two parameters: the name of the dataset and the type="l"
argument.
plot(<data>, type="l") # Syntax structure
In the example below, we will generate a line plot showing the daily sales of a store over 30 days.
# We use a custom dataset in this exercisehead(sales_data) # Preview of the dataplot(sales_data$sales,type='l') # Define the data and the plot style.
Notice that although the chart shows the change in data over time, we did not provide ...