43  Line plots

Line plots (or line graphs) are a staple in data visualization, particularly useful for displaying data trends and variations over time. They help data analysts understand how data points connect over a period or sequence, which is crucial for identifying patterns such as trends, cycles, and potential anomalies.

43.1 Utility of Line Plots in Data Analysis:

  1. Trend Identification: Line plots are excellent for observing trends in data across time, such as sales data over the months or years, temperature changes through seasons, or stock market fluctuations.

  2. Comparison: Analysts can plot multiple lines on the same graph to compare trends across different categories or groups, making it easier to evaluate relative performance or behaviors.

  3. Temporal Changes: Line plots are inherently suited to data that changes continuously and is dependent on a sequential order, particularly time series data.

  4. Smoothing and Forecasting: They can be used to apply smoothing techniques to reduce noise and better highlight underlying trends, and to project future values based on historical data trends.

43.2 Single-Series Line Plot

Our first example shows how a single metric — monthly sales — moves across six months. The line carries direction, and the markers highlight each recorded observation.

43.3 Line Plot using R and Python

The line moves upward on aggregate with a small dip in March. Using one colour for both the line and the markers keeps the chart visually quiet so the shape of the trend dominates.

43.4 Multi-Line Comparison

Line plots really shine when several series are compared on the same axes. Each region gets its own line, letting you read absolute levels and relative trends at the same time.

43.5 Multi-Line Comparison using R and Python

Combining colour and line style keeps the series distinguishable even in black-and-white print or for readers with colour-vision differences. East is the strongest region across the period, while South sits consistently below the other two.

43.6 Line Plot with a Moving Average

Real-world time series are noisy. Overlaying a moving average (here, a three-month rolling mean) smooths short-term bumps so the underlying trend stands out.

43.7 Line Plot with Moving Average using R and Python

The grey line is what you actually observed; the red line is the smoothed story. The moving average hugs the underlying upward trend and ignores month-to-month noise, which is exactly what you want before forecasting.


Summary

Concept Description
Foundations
Line Plot A chart that connects observations with straight line segments to reveal how a value changes across an ordered sequence
Ordered X-axis Line plots require an ordered x-axis, typically time, so the connecting lines carry meaning
Points Connected by Segments Each observation becomes a point, and adjacent points are joined to show the path of the series
What Line Plots Reveal
Trend Identification Rising or falling lines summarise overall direction across the period of interest
Comparison of Multiple Series Several lines on the same axes allow side-by-side comparison of categories or groups
Temporal Changes Line plots are the natural choice for continuous, sequence-dependent data such as daily or monthly values
Smoothing and Forecasting Overlaying a moving average or fitted curve reduces noise and clarifies the underlying signal
Time-Series Insight
Time-Series Patterns Recurring shapes such as peaks, troughs and plateaus tell stories about the process generating the data
Cycles and Seasonality Regular ups and downs at fixed intervals suggest seasonality worth modelling explicitly
Anomaly Detection Sharp breaks or spikes stand out against the smooth trend and flag observations that deserve review
In R and Python
R via ggplot2 geom_line Use ggplot(data, aes(x, y)) + geom_line() + geom_point() for polished line plots in R
R via Base plot() and lines() Use plot(x, y, type = 'l') and lines() to add extra series in base R
Python via plt.plot() Use matplotlib.pyplot.plot(x, y, marker = 'o') for a Python line plot with markers
Presentation
Markers and Gridlines Markers make individual observations visible, while gridlines aid precise value reading
Axis Labels and Titles Always label the x-axis with units of time, label the y-axis with units of measure, and give the plot a clear title