plot函数--R语言

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函数

  • 9
    点赞
  • 45
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值