| 42333 |
ripley |
1 |
% File src/library/graphics/man/rect.Rd
|
| 68948 |
ripley |
2 |
% Part of the R package, https://www.R-project.org
|
| 59526 |
ripley |
3 |
% Copyright 1995-2012 R Core Team
|
| 42333 |
ripley |
4 |
% Distributed under GPL 2 or later
|
|
|
5 |
|
| 27442 |
ripley |
6 |
\name{rect}
|
| 28956 |
maechler |
7 |
\title{Draw One or More Rectangles}
|
| 27442 |
ripley |
8 |
\usage{
|
|
|
9 |
rect(xleft, ybottom, xright, ytop, density = NULL, angle = 45,
|
| 36121 |
ripley |
10 |
col = NA, border = NULL, lty = par("lty"), lwd = par("lwd"),
|
| 36116 |
ripley |
11 |
\dots)
|
| 27442 |
ripley |
12 |
}
|
| 56186 |
murdoch |
13 |
\alias{rect}
|
| 27442 |
ripley |
14 |
\arguments{
|
|
|
15 |
\item{xleft}{a vector (or scalar) of left x positions.}
|
|
|
16 |
\item{ybottom}{a vector (or scalar) of bottom y positions.}
|
|
|
17 |
\item{xright}{a vector (or scalar) of right x positions.}
|
|
|
18 |
\item{ytop}{a vector (or scalar) of top y positions.}
|
|
|
19 |
\item{density}{the density of shading lines, in lines per inch.
|
|
|
20 |
The default value of \code{NULL} means that no shading lines are drawn.
|
|
|
21 |
A zero value of \code{density} means no shading lines whereas
|
|
|
22 |
negative values (and \code{NA}) suppress shading (and so allow
|
|
|
23 |
color filling).}
|
|
|
24 |
\item{angle}{angle (in degrees) of the shading lines.}
|
|
|
25 |
\item{col}{color(s) to fill or shade the rectangle(s) with.
|
| 36121 |
ripley |
26 |
The default \code{NA} (or also \code{NULL}) means do not fill,
|
| 27442 |
ripley |
27 |
i.e., draw transparent rectangles, unless \code{density} is specified.}
|
| 36121 |
ripley |
28 |
\item{border}{color for rectangle border(s). The default means
|
|
|
29 |
\code{par("fg")}. Use \code{border = NA} to omit borders.
|
| 39762 |
murrell |
30 |
If there are shading
|
|
|
31 |
lines, \code{border = TRUE} means use the same colour for
|
|
|
32 |
the border as for the shading lines.}
|
| 28950 |
ripley |
33 |
\item{lty}{line type for borders and shading; defaults to \code{"solid"}.}
|
| 59526 |
ripley |
34 |
\item{lwd}{line width for borders and shading. Note that the use of
|
|
|
35 |
\code{lwd = 0} (as in the examples) is device-dependent.}
|
| 56113 |
ripley |
36 |
\item{\dots}{\link{graphical parameters} such as \code{xpd}, \code{lend},
|
| 36222 |
ripley |
37 |
\code{ljoin} and \code{lmitre} can be given as
|
|
|
38 |
arguments.}
|
| 27442 |
ripley |
39 |
}
|
|
|
40 |
\description{
|
|
|
41 |
\code{rect} draws a rectangle (or sequence of rectangles) with the
|
|
|
42 |
given coordinates, fill and border colors.
|
|
|
43 |
}
|
|
|
44 |
\details{
|
|
|
45 |
The positions supplied, i.e., \code{xleft, \dots},
|
|
|
46 |
are relative to the current plotting region. If the x-axis goes from
|
|
|
47 |
100 to 200 then \code{xleft} must be larger than 100 and \code{xright}
|
| 45364 |
ripley |
48 |
must be less than 200. The position vectors will be recycled to the
|
|
|
49 |
length of the longest.
|
| 27442 |
ripley |
50 |
|
| 45364 |
ripley |
51 |
It is a graphics primitive used in \code{\link{hist}},
|
| 27442 |
ripley |
52 |
\code{\link{barplot}}, \code{\link{legend}}, etc.
|
|
|
53 |
}
|
|
|
54 |
\seealso{
|
| 42961 |
ripley |
55 |
\code{\link{box}} for the standard box around the plot;
|
| 27442 |
ripley |
56 |
\code{\link{polygon}} and \code{\link{segments}} for flexible line
|
|
|
57 |
drawing.
|
|
|
58 |
|
|
|
59 |
\code{\link{par}} for how to specify colors.
|
|
|
60 |
}
|
|
|
61 |
\examples{
|
| 41502 |
ripley |
62 |
require(grDevices)
|
| 27442 |
ripley |
63 |
## set up the plot region:
|
|
|
64 |
op <- par(bg = "thistle")
|
| 61153 |
ripley |
65 |
plot(c(100, 250), c(300, 450), type = "n", xlab = "", ylab = "",
|
| 27442 |
ripley |
66 |
main = "2 x 11 rectangles; 'rect(100+i,300+i, 150+i,380+i)'")
|
|
|
67 |
i <- 4*(0:10)
|
| 36816 |
ripley |
68 |
## draw rectangles with bottom left (100, 300)+i
|
|
|
69 |
## and top right (150, 380)+i
|
| 61168 |
ripley |
70 |
rect(100+i, 300+i, 150+i, 380+i, col = rainbow(11, start = 0.7, end = 0.1))
|
| 61153 |
ripley |
71 |
rect(240-i, 320+i, 250-i, 410+i, col = heat.colors(11), lwd = i/5)
|
| 27442 |
ripley |
72 |
## Background alternating ( transparent / "bg" ) :
|
|
|
73 |
j <- 10*(0:5)
|
| 36816 |
ripley |
74 |
rect(125+j, 360+j, 141+j, 405+j/2, col = c(NA,0),
|
|
|
75 |
border = "gold", lwd = 2)
|
| 27442 |
ripley |
76 |
rect(125+j, 296+j/2, 141+j, 331+j/5, col = c(NA,"midnightblue"))
|
| 74363 |
maechler |
77 |
mtext("+ 2 x 6 rect(*, col = c(NA,0)) and col = c(NA,\"m..blue\")")
|
| 27442 |
ripley |
78 |
|
|
|
79 |
## an example showing colouring and shading
|
| 61153 |
ripley |
80 |
plot(c(100, 200), c(300, 450), type= "n", xlab = "", ylab = "")
|
| 27442 |
ripley |
81 |
rect(100, 300, 125, 350) # transparent
|
| 61153 |
ripley |
82 |
rect(100, 400, 125, 450, col = "green", border = "blue") # coloured
|
|
|
83 |
rect(115, 375, 150, 425, col = par("bg"), border = "transparent")
|
|
|
84 |
rect(150, 300, 175, 350, density = 10, border = "red")
|
|
|
85 |
rect(150, 400, 175, 450, density = 30, col = "blue",
|
|
|
86 |
angle = -30, border = "transparent")
|
| 27442 |
ripley |
87 |
|
| 61153 |
ripley |
88 |
legend(180, 450, legend = 1:4, fill = c(NA, "green", par("fg"), "blue"),
|
|
|
89 |
density = c(NA, NA, 10, 30), angle = c(NA, NA, 30, -30))
|
| 27442 |
ripley |
90 |
|
|
|
91 |
par(op)
|
|
|
92 |
}
|
|
|
93 |
\keyword{aplot}
|