Line Graph

What is a line graph?

A line graph is a simple way to visually communicate how the measured values of a continuous variable change over time. A line graph may also be called a line chart, a trend plot, run chart or a time series plot.

See how to create a line graph using statistical software

Line graphs show changes over time

Line graphs show how a continuous variable changes over time. The variable that measures time is plotted on the x-axis. The continuous variable is plotted on the y-axis.

Line graph examples

Example 1: Basic line graph

The graph in Figure 1 shows the weight change for a parrot measured at points over time. The data points and the line are both shown. You might want to omit the points. The weight axis makes sense for the data. It also has useful axis labels. The graph allows you to visualize how the weight of the parrot, measured in grams, changes over time.

In quality control, a basic line graph, like the one below, is called a run chart. This shows the “run over time” for the values of the variable on the y-axis.

Figure 1: Basic line graph showing weight change over time

Example 2: Accounting for missing values

The line graph in Figure 2 also uses parrot weight data. In this case, the parrot was not weighed on some days as planned. This line graph does not connect across the missing values. We have also added an annotation to highlight the fact that the line graph has missing values. Alternatively, you can connect through missing values or use a dotted line for the connection across missing values. It is important to be aware of missing values and how you display them in your graphic.

Figure 2: Line graph with missing values

Example 3: When to use a regression instead of a line graph

The graph in Figure 3 shows a scatter plot of two continuous variables. The x-axis shows body weight; the y-axis shows sleep time. The graph also shows the points connected with a line, which is not correct. The points are for different species of animals and do not have a relationship that shows changes over time. The graph in Figure 4 shows a scatter plot with a simple linear regression, which is a correct way to display these data.

Figure 3: Inappropriate use of a line graph
Figure 4: This scatter plot with linear regression is more useful than the line graph in Figure 3

Example 4: Consider your y-axis scale

When creating a line graph, or any graph, be cognizant of your scales. For instance, in the past, books recommended including zero on the y-axis. Current practice dictates using zero only when it makes sense for your data. Figure 5 shows historical data for hotel room occupancy rates in Australia for the fourth quarter of several years. The y-axis follows the historical recommendation of an axis that starts at zero. The problem with this approach is that it minimizes the visual impact of year-to-year differences. Compare Figures 5 and 6. Figure 6 uses a more reasonable set of values for the y-axis range so that it is easier to see the peak in 2006. Most software tools automatically create a y-axis that makes sense for the data. Some software tools allow you to change the axes.

Figure 5: Line graph with zero on the y-axis
Figure 6: The difference between years is easier to discern when zero is not included on the y-axis

Example 5: Multiple lines for different categories

Line graphs can include multiple lines. The graph in Figure 7 shows historical market share data for smart phone operating systems from 2006 (when the first smartphones were released) until 2011. Each line shows the change over time for the different operating systems. 

Figure 7: Multiple lines on a single line graph, coded by color

When creating line graphs with multiple lines, be sure to consider the colors used, based on how the graph will be shared and viewed. Will it always be in color? Will it be in black and white? Make sure that the colors are obviously different even when printing without color. Using different line styles in addition to, or instead of, color is another option. While a legend can be helpful when there are only a few lines, it is less so when a graph has many lines. Legends are helpful, however, when using another variable to define the different lines in the graph. 

The line graph in Figure 7 uses two solid lines in different colors for the two operating systems where the market share increased over time. The colors vary enough to be easily distinguished when printed in black and white. The graph uses two different dashed lines for the two operating systems where the market share decreased over time. The graph also uses a legend in the upper-left corner. 

Line graphs and types of data

For a line graph, the variable on the x-axis defines time. Most software tools store this variable as a continuous variable.

Continuous data: appropriate for a line graph

Line graphs make sense for continuous data on the y-axis, since continuous data are measured on a scale with many possible values. Some examples of continuous data are:

  • Age
  • Blood pressure
  • Weight
  • Temperature
  • Speed

For all of these examples, a line graph is an appropriate graphical tool to visualize changes in a variable over time.

Categorical or nominal data: choose another chart type

Line graphs do not make sense for categorical or nominal data on the y-axis, since these types of data are measured on a scale with specific values.

With categorical data, the sample is divided into groups and the responses might have a defined order. For example, in a survey where you are asked to give your opinion on a scale from “Strongly Disagree” to “Strongly Agree,” your responses are categorical.

For nominal data, the sample is also divided into groups but there is no particular order. Country of residence is an example of a nominal variable. You can use the country abbreviation, or you can use numbers to code the country name. Either way, you are simply naming the different groups of data.

You can use categorical or nominal variables as a grouping variable to add multiple groups using multiple lines to a line graph as shown in Figure 7.