1. 函数功能
Generic function for plotting of R objects.
For simple scatter plots, plot.default will be used.
However, there are plot methods for many R objects, including functions, data.frames, density objects, etc.
Use methods(plot) and the documentation for these.
用于绘制R对象的通用函数。
对于简单的散点图,将使用plot.default。
2.函数语法
plot(x, y, ...)
3. 函数参数
3.1 : X
x
the coordinates of points in the plot.
Alternatively, a single plotting structure, function or any R object
with a plot method can be provided.
图中点的坐标。
3.2: y
y
the y coordinates of points in the plot,
optional if x is an appropriate structure.
绘图中点的y坐标
x,y可以都给,当只给出x,则绘图时默认x为y,生成x关于下标的图形
a <- sample(1:100,10)
plot(a)
3.3 : …
Arguments to be passed to methods
Many methods will accept the following arguments:
要传递给方法的参数
许多方法将接受以下参数:
3.3.1 : type
type
what type of plot should be drawn. Possible types are:
绘制图形的类型,取值有:
"p" for points,
"l" for lines,
"b" for both,
"c" for the lines part alone of "b",
"o" for both ‘overplotted’,
"h" for ‘histogram’ like (or ‘high-density’) vertical lines,
"s" for stair steps,
"S" for other steps, see ‘Details’ below,
"n" for no plotting.
默认绘制散点图
plot(sale$日期,sale$销量)
type=‘l’,绘制线图
plot(sale$日期,sale$销量,type='l')
type=‘b’,同时绘制散点和折线图
plot(sale$日期,sale$销量,type='b')
type=‘c’,只要type='b’的折线部分,散点去除
plot(sale$日期,sale$销量,type='c')
type=‘o’,同时绘制点和线,且线穿过点
plot(sale$日期,sale$销量,type='o')
type=‘h’,绘制出点到横坐标轴的垂直线;
plot(sale$日期,sale$销量,type='h')
type=‘s’, 绘制出阶梯图(先横后纵)
plot(sale$日期,sale$销量,type='s')
type=‘S’,绘制出阶梯图(先纵后横)
plot(sale$日期,sale$销量,type='S')
type=‘n’,没有散点,仅显示框架
plot(sale$日期,sale$销量,type='n')
3.3.2 :main
main
an overall title for the plot
图形标题
plot(sale$日期,sale$销量,type='b',
main='每日用餐人数折线图')
3.3.3 :sub
sub
a sub title for the plot
图形的子标题
plot(sale$日期,sale$销量,type='b',
main='每日用餐人数折线图',sub='图1')
3.3.4 :xlab
xlab
a title for the x axis
x轴标题
plot(sale$日期,sale$销量,type='b',
main='每日用餐人数折线图',sub='图1',
xlab='日期')
3.3.5 : ylab
ylab
a title for the y axis
y轴标题
plot(sale$日期,sale$销量,type='b',
main='每日用餐人数折线图',sub='图1',
xlab='日期',ylab='销量')
3.3.6: asp
asp
the y/x aspect ratio
官方文档: plot函数