# 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

- Download JMP to follow along using the sample data included with the software.
- To see more JMP tutorials, visit the JMP Learning Library.

## 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.

### 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.

### 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.

### 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.

### 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.

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.