September 2017
Beginner to intermediate
560 pages
25h 18m
English
Using the following code, you can first generate the scatterplot and then color the points with different colors corresponding to different values of cylinders. Note that mpg and weight are in different orders in the plot and points function invocations. This is because in plot, we ask the system to plot mpg as a function of weight, whereas in the points function, we just supply a set of (x,y) coordinates to plot.
> # first generate the empty plot > # to get the axes for the whole dat > plot(mpg ~ horsepower, type = "n") > # Then plot the points in different colors > with(subset(auto, cylinders == "8cyl"), points(horsepower, mpg, col = "blue")) > with(subset(auto, cylinders == "6cyl"), points(horsepower, ...
Read now
Unlock full access