R语言低级绘图函数-rect

R语言低级绘图函数-rectrect 函数用来在一张图上添加矩形,只需要指定左下角和右上角的坐标的位置,就可以画出一个矩形 基本用法: plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n") rect(xleft = 1, ybottom = 1,

rect 函数用来在一张图上添加矩形,只需要指定左下角和右上角的坐标的位置,就可以画出一个矩形

基本用法:

plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n")
rect(xleft = 1, ybottom = 1, xright = 5, ytop = 5)

效果图如下:

R语言低级绘图函数-rect

xleft, ybottom, xright, ytop 支持一次设置多个值,同时创建多个矩形,用法如下:

plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n")
rect(xleft = c(1, 2), ybottom = c(1, 2), xright = c(5, 4), ytop = c(5, 4))

效果图如下:

R语言低级绘图函数-rect

参数设置:

border : 设置矩形边框的颜色,默认为”black”, 支持为多个矩形设置不同的值

代码示例:

plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n")
rect(xleft = c(1, 2), ybottom = c(1, 2), xright = c(5, 4), ytop = c(5, 4), border = c("red", "blue"))

效果图如下:

R语言低级绘图函数-rect

col : 设置矩形的填充色,默认为NULL, 表示无填充色,, 支持为多个矩形设置不同的值

plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n")
rect(xleft = c(1, 2), ybottom = c(1, 2), xright = c(5, 4), ytop = c(5, 4), col = c("pink", "green"))

效果图如下:

R语言低级绘图函数-rect

density 和 angle : 搭配使用,设置用线条填充矩形,angle 设置线条的角度,默认为45, density 设置填充线条的密度,数值越大越密集

代码示例:

par(mfrow = c(1,3))
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "density = 1")
rect(xleft = 1, ybottom = 1, xright = 5, ytop = 5, angle = 45, density = 1)
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "density = 3")
rect(xleft = 1, ybottom = 1, xright = 5, ytop = 5, angle = 45, density = 2)
plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n", main = "density = 4")
rect(xleft = 1, ybottom = 1, xright = 5, ytop = 5, angle = 45, density = 3) 

效果图如下:

R语言低级绘图函数-rect

lwd:  设置矩形所有线条的宽度

代码示例:

plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n")
rect(xleft = 1, ybottom = 1, xright = 5, ytop = 5, angle = 45, density = 2, lwd = 3)

效果图如下:

R语言低级绘图函数-rect

lty: 设置矩形所有线条的类型

代码示例:

plot(1:5, 1:5, xlim = c(0,6), ylim = c (0,6), type = "n")
rect(xleft = 1, ybottom = 1, xright = 5, ytop = 5, angle = 45, density = 2, lwd = 2, lty = 3)

效果图如下:

R语言低级绘图函数-rect

今天的文章R语言低级绘图函数-rect分享到此就结束了,感谢您的阅读,如果确实帮到您,您可以动动手指转发给其他人。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:http://bianchenghao.cn/56338.html

(0)
编程小号编程小号
上一篇 2023-08-26 20:30
下一篇 2023-08-26 21:06

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注