The regression example on the Intro to R page can be complicated so we have several lines and need different colors to distinguish them.
For now, never mind the details of how this works. What it does is do a linear regression (black line) and a quadratic regression (red curved line) and draw both on the scatter plot.
We'll learn how to do this stuff in the second half of the course.
For now, the only point is the col = "red"
part of
the commands, which directs R to make something (the quadratic
regression curve drawn by the curve
function) red.
If you don't like the colors I pick, you can change them.
prints all the color names that R knows about, 657 of them.
To see just the varieties of green do
One student last year wanted shades of gray instead of colors because he didn't want to use a color printer.
If you want gray instead of a color use some variant of gray
(changing "green"
to "gray"
in the example
above shows all the shades of gray available) or just pick a number
"gray0"
and "gray100"
and gray
with
all the numbers in between are valid color names.
Not really about colors, but another way to distinguish lines, is
what R calls line types
meaning dotted, dashed and so forth.
These can be specified by using the optional argument lty
to plot commands. Possible values are
"blank"
, "solid"
, "dashed"
,
"dotted"
, "dotdash"
,
"longdash"
, or "twodash"
,
where "blank"
uses invisible
lines
(i. e., doesn't draw them).
For example, we can redo our regression example above as
The solid line is the linear regression line, the dashed curve is the quadratic regression function.