Session Ready
Exercise

Using the legend() function

The video described and illustrated the use of the legend() function to add explanatory text to a plot.

This exercise asks you to first create a scatterplot and then use this function to add explanatory text for the point shapes that identify two different data subsets.

Instructions
100 XP
  • Set up a scatterplot of Gas vs. Temp from the whiteside data frame using type = "n" option in the plot() call. Label the x-axis "Outside temperature" by specifying the xlab argument and the y-axis "Heating gas consumption" by specifying the ylab argument.
  • 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".
  • Using the points() function, add the "Before" points to the plot, represented as solid triangles.
  • Using the points() function, add the "After" points to the plot, represented as open circles.
  • Using the legend() function, add a legend in the upper right corner of the plot with the names "Before" and "After" and the appropriate point shapes indicated.