Exercise

# The points() function and point types

One advantage of specifying the `pch`

argument locally is that, in a call to functions like `plot()`

or `points()`

, local specification allows us to make `pch`

depend on a variable in our dataset. This provides a simple way of indicating different data subsets with different point shapes or symbols.

This exercise asks you to generate two plots of `mpg`

vs. `hp`

from the `mtcars`

data frame in the `datasets`

package. The first plot specifies the point shapes using numerical values of the `pch`

argument defined by the `cyl`

variable in the `mtcars`

data frame. The second plot illustrates the fact that `pch`

can also be specified as a vector of *single characters*, causing each point to be drawn as the corresponding character.

Instructions

**100 XP**

- Create an empty plot of
`mpg`

vs.`hp`

using the`type = "n"`

option from the`mtcars`

data frame, with axis labels`"Horsepower"`

and`"Gas mileage"`

. - Using the
`points()`

function, add the`mpg`

vs.`hp`

data, with`pch`

specified by the numeric values of`cyl`

. - Repeat both of the previous steps, except with
`pch`

specified by the character values of`cyl`

.