Subsections:

This section describes how to use a line plot to observe the behavior of one or more variables over time. You can also use line plots to visualize a response variable (and, optionally, fitted curves and confidence bands) versus values of an explanatory variable.

You can create line plots when your data are in one of two configurations. The first configuration (Table 6.1) is when you have an X variable and one or more Y variables. Each Y variable has the same number of observations as the X variable. (Some of the Y values might be missing.) In this configuration there are as many lines in the plot as there are Y variables.

In the second configuration (Table 6.2), there is a single X and a single Y variable, but there are one or more *group* variables that specify which line each observation belongs to. In this configuration there are as many lines in the plot
as there are unique values of the group variables.

Table 6.2: An Alternative Data Configuration for a Line Plot

X |
Y |
Group |
---|---|---|

1 |
1 |
A |

1 |
4 |
B |

2 |
3 |
A |

2 |
3 |
B |

3 |
2 |
A |

3 |
3 |
B |

4 |
4 |
A |

4 |
2 |
B |

5 |
5 |
A |

5 |
1 |
B |

The X variable does not need to be sorted in either configuration. Any data arranged in the first configuration can be rewritten in the second. For example, Table 6.2 represents the same data as Table 6.1. The second configuration is more useful if you have different values of the X variable for each group.