7.4 Adding Line Segments and Arrows

7.4.1 Problem

You want to add line segments or arrows to a plot.

7.4.2 Solution

Use annotate("segment"). In this example, we’ll use the climate data set and use a subset of data from the Berkeley source (Figure 7.10):

Line segment annotation

Figure 7.10: Line segment annotation

7.4.3 Discussion

It’s possible to add arrowheads or flat ends to the line segments, using arrow() from the grid package. In this example, we’ll do both (Figure 7.11):

Line segments with arrow heads

Figure 7.11: Line segments with arrow heads

The default angle is 30, and the default length of the arrowhead lines is 0.2 inches.

If one or both axes are discrete, the x and y positions are such that the categorical items have coordinate values 1, 2, 3, and so on.

7.4.4 See Also

For more information about the parameters for drawing arrows, load the grid package and see ?arrow.