The RECT function is used to add a rectangle to a graph, so you can draw a rectangle by specifying the position of the lower-left and upper-right coordinates.
Basic usage:
Plot (1:5, 1:5, Xlim = C (0,6), Ylim = C (0,6), type = "n") rect (xleft = 1, Ybottom = 1, xright = 5, ytop = 5)
As follows:
Xleft, Ybottom, Xright, Ytop supports setting multiple values at once, creating multiple rectangles, using the following:
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))
As follows:
Parameter settings:
Border: Sets the color of the rectangle border, default to "Black", supports setting different values for multiple rectangles
code example:
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"))
As follows:
Col: Sets the fill color of the rectangle, default is null, indicates no fill color, supports setting different values for multiple rectangles
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"))
As follows:
Density and angle: With use, set to fill the rectangle with lines, angle set the angle of the line, default to three, density set the density of the fill line, the larger the more dense
code example:
As follows:
LWD: Sets the width of all lines in the rectangle
code example:
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 = $, de Nsity = 2, LWD = 3)
As follows:
Lty: Sets the type of all lines in the rectangle
code example:
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 = $, de Nsity = 2, LWD = 2, lty = 3)
As follows:
R language Low-level drawing function-rect