虽然在R中生成绘图的最常用函数是 plot ,但您可以在 ?par 文档下找到最有用的信息 . 在其中,有一个 Color Specification 部分描述了如何为绘图设置颜色 . 这里有一段摘录:
Colors can be specified in several different ways. The simplest
way is with a character string giving the color name (e.g.,
‘"red"’). A list of the possible colors can be obtained with the
function ‘colors’. Alternatively, colors can be specified
directly in terms of their RGB components with a string of the
form ‘"#RRGGBB"’ where each of the pairs ‘RR’, ‘GG’, ‘BB’ consist
of two hexadecimal digits giving a value in the range ‘00’ to
‘FF’. Colors can also be specified by giving an index into a
small table of colors, the ‘palette’: indices wrap round so with
the default palette of size 8, ‘10’ is the same as ‘2’. This
provides compatibility with S. Index ‘0’ corresponds to the
background color. Note that the palette (apart from ‘0’ which is
per-device) is a per-session setting.
请注意,在您的情况下,您没有将 character 传递给 col 参数,而是 factor ,它基本上是一个整数值 . 此外,您可以指定与要绘制的点数一样多的颜色,这样您就可以声明每个点的颜色 .
希望这可以帮助 .