Session Ready
Exercise

Rotating text with the srt argument

In addition to the optional arguments used in the previous exercises, the text() function also supports a number of other optional arguments that can be used to enhance the text. This exercise uses the cex argument to reduce the text size and introduces two new arguments. The first is the col argument that specifies the color used to display the text, and the second is the srt argument that allows us to rotate the text.

Color has been used in several of the previous exercises to specify point colors, and the effective use of color is discussed further in Chapter 5. One of the points of this exercise is to show that the specification of text color with the text() function is essentially the same as the specification of point color with the plot() function. As a specific example, setting col = "green" in the text() function causes the text to appear in green. If col is not specified, the text appears in the default color set by the par() function, which is typically black.

The srt parameter allows us to rotate the text through an angle specified in degrees. The typical default value (set by the par() function) is 0, causing the text to appear horizontally, reading from left to right. Specifying srt = 90 causes the text to be rotated 90 degrees counter-clockwise so that it reads from bottom to top instead of left to right.

Instructions
100 XP
  • Create a scatterplot of Gas vs. Temp from the whiteside data frame, as solid triangles.
  • Use the which() function to create a vector indexB that points to all data observations with Insul having the value "Before".
  • Use the which() function to create a vector indexA that points to all data observations with Insul having the value "After".
  • Use the text() function to overlay the text "Before" on the appropriate points, in blue, rotated 30 degrees, reducing the text size to 80 percent of the default.
  • Use the text() function to overlay the text "After" on the appropriate points, in red, rotated -20 degrees, reducing the text size to 80 percent of the default.