Session Ready
Exercise

Using the bagplot() function

A single box plot gives a graphical representation of the range of variation in a numerical variable, based on five numbers:

  • The minimum and maximum values
  • The median (or "middle") value
  • Two intermediate values called the lower and upper quartiles

In addition, the standard box plot computes a nominal data range from three of these numbers and flags points falling outside this range as outliers, representing them as distinct points.

The bag plot extends this representation to two numerical variables, showing their relationship, both within two-dimensional "bags" corresponding to the "box" in the standard boxplot, and indicating outlying points outside these limits.

This exercise asks you to construct, first, side-by-side box plots of the Min.Price and Max.Price variables from the mtcars dataset, and then to use the bagplot() function from the aplpack package to construct the corresponding bag plot.

Instructions 1/2
undefined XP
  • 1

    Use the boxplot() function to construct side-by-side box plots for Min.Price and Max.Price from the Cars93 data frame.

    • 2
      • Load the aplpack package to make the bagplot() function available.
      • Construct the bag plot showing the relationship between the Min.Price and Max.Price variables from the Cars93 data frame. Set the cex parameter to 1.2 to make the point sizes larger.
      • Use the abline() function to add a dashed equality reference line with intercept 0 and slope 1.