R语言-散布图—plot的函数使用

plot()的使用

注意:用到的数据(自行下载):

首先,这个就是先help一下,这是新手必须要学会的
在这里插入图片描述
会产生一以下代码帮助:
|

Generic X-Y Plotting
Description
Generic function for plotting of R objects. For more details about the graphical parameter arguments, see par.

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.

Usage
plot(x, y, ...)
Arguments
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.

y	
the y coordinates of points in the plot, optional if x is an appropriate structure.

...	
Arguments to be passed to methods, such as graphical parameters (see par). Many methods will accept the following arguments:

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.

All other types give a warning or an error; using, e.g., type = "punkte" being equivalent to type = "p" for S compatibility. Note that some methods, e.g. plot.factor, do not accept this.

main
an overall title for the plot: see title.

sub
a sub title for the plot: see title.

xlab
a title for the x axis: see title.

ylab
a title for the y axis: see title.

asp
the y/x aspect ratio, see plot.window.

Details
The two step types differ in their x-y preference: Going from (x1,y1) to (x2,y2) with x1 < x2, type = "s" moves first horizontal, then vertical, whereas type = "S" moves the other way around.

See Also
plot.default, plot.formula and other methods; points, lines, par. For thousands of points, consider using smoothScatter() instead of plot().

For X-Y-Z plotting see contour, persp and image.

Examples
require(stats) # for lowess, rpois, rnorm
plot(cars)
lines(lowess(cars))
plot(sin, -pi, 2*pi) # see ?plot.function

## Discrete Distribution Plot:
plot(table(rpois(100, 5)), type = "h", col = "red", lwd = 10,
     main = "rpois(100, lambda = 5)")

## Simple quantiles/ECDF, see ecdf() {library(stats)} for a better one:
plot(x <- sort(rnorm(47)), type = "s", main = "plot(x, type = \"s\")")
points(x, cex = .5, col = "dark red")
[Package graphics version 3.6.1 Index]

接下来用个例子说明用法:

setwd("F:\\R语言\\Code\\Chapter 1\\Data Files")
#设置切换到目录
sales <- read.csv("dailysales.csv", header = TRUE)
#把文件读进来,用变sales接收
plot(
  sales$units ~ as.Date(sales$date, "%d/%m/%y"),
  #plot散点图
  type = "l",
  #图形为连线图,l为连线
  main = "Unit Sales in the month of Januanry",
  #标题
  xlab = "Data",
  #横坐标叫什么
  ylab = "NUmber of units sold ",
  #纵坐标叫什么
  col = "red"
  #颜色
)

效果:
在这里插入图片描述
完毕。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值