Session Ready
Exercise

Using the supsmu() function to add smooth trend curves

As we saw in the video, some scatterplots exhibit fairly obvious trends that are not linear. In such cases, we may want to add a curved trend line that highlights this behavior of the data and the supsmu() function represents one way of doing this.

To use this function, we need to specify values for the required arguments x and y, but it also has a number of optional arguments. Here, we consider the optional bass argument, which controls the degree of smoothness in the resulting trend curve. The default value is 0, but specifying larger values (up to a maximum of 10) results in a smoother curve. This exercise asks you to use the supsmu() function to add two trend lines to a scatterplot, one using the default parameters and the other with increased smoothness.

Instructions
100 XP
  • Create a scatterplot of MPG.city vs. Horsepower from the Cars93 data frame.
  • Create a supsmu() object named trend1 with the bass parameter at its minimum (default) value, 0.
  • Use the lines() function to add the trend1 curve to the plot as a solid line. There is no need to provide additional arguments.
  • Create a supsmu() object named trend2 with the bass parameter at its maximum value, 10.
  • Use the lines() function to add the trend2 curve to the plot as a dotted line of twice standard width.