Session Ready
Exercise

Using the text() function to label plot features

One of the main uses of the text() function is to add informative labels to a data plot. The text() function takes three arguments:

  • x, which specifies the value for the x variable,
  • y, which specifies the value for the y variable, and
  • label, which specifies the label for the x-y value pair.

This exercise asks you to first create a scatterplot of city gas mileage versus horsepower from the Cars93 data, then identify an interesting subset of the data (i.e. the 3-cylinder cars) and label these points. You will find that assigning a vector to the x, y, and label arguments to text() will result in labeling multiple points at once.

Instructions
100 XP
  • Create a scatterplot of MPG.city vs. Horsepower from the Cars93 data frame, with points represented as solid squares. Recall that the pch value for solid squares is 15.
  • Create the variable index3 using the which() function that identifies all 3-cylinder cars.
  • Label the Make of each 3-cylinder car in the Cars93 data frame using the text() function. Use the adj argument to specify left-justified text in your labels.
  • Use the zoom feature in the Plots window to see this plot more clearly.