-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathrect.R
More file actions
56 lines (52 loc) · 2.19 KB
/
rect.R
File metadata and controls
56 lines (52 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#' gsplot rect
#'
#' Add single or multiple rectangles to the plotting region. See \code{\link[graphics]{rect}} for more details.
#'
#' @param object gsplot object
#' @param \dots Further graphical parameters may also be supplied as arguments. See 'Details'.
#'
#' @details Additional graphical parameter inputs:
#' \itemize{
#' \item{\code{xleft}} {vector or scalar indicating left positions on the x-axis}
#' \item{\code{xright}} {vector or scalar indicating right positions on the x-axis}
#' \item{\code{ybottom}} {vector or scalar indicating bottom positions on the y-axis}
#' \item{\code{ytop}} {vector or scalar indicating top positions on the y-axis}
#' \item{\code{density}} {density of shading lines (lines per inch), NULL means no shading, NA suppresses shading and allows color fill}
#' \item{\code{angle}} {angle of shading lines (degrees)}
#' \item{\code{col}} {shade or fill color(s), NA means no fill (transparent)}
#' \item{\code{border}} {color of border, NA means no border, TRUE indicates the same color as shading lines}
#' \item{\code{lty}} {line type for borders and shading}
#' \item{\code{lwd}} {line width for borders and shading}
#' }
#'
#' @rdname rect
#' @export
#' @examples
#' gs <- gsplot() %>%
#' points(x=c(1:5, 3.5), y=c(1:5, 6), legend.name="Stuff") %>%
#' lines(x=2:6, y=2:6, ylim=c(0,10)) %>%
#' axis(side=c(1,2),labels=TRUE) %>%
#' legend("topright") %>%
#' rect(xleft=3.4, xright=3.6, ybottom=5,
#' ytop=7, density=NULL, border='purple',
#' lty=2, lwd=3)
#' gs
#'
#' gs <- gsplot() %>%
#' lines(x=10:20, y=c(10:15, 25, 17:20),
#' xlim=c(0,30), ylim=c(0,30), col='darkgreen',
#' legend.name="Some data") %>%
#' rect(xleft=15, xright=17, ybottom=21, ytop=27,
#' density=10, angle=130, col='darkblue') %>%
#' legend()
#' gs
rect <- function(object, ...) {
override("graphics", "rect", object, ...)
}
rect.gsplot <- function(object, ..., legend.name=NULL, side=c(1,2)){
fun.name <- "rect"
to.gsplot <- list(list(arguments = set_args(fun.name, ...),
gs.config=list(legend.name = legend.name, side = side))) %>%
setNames(fun.name)
return(gsplot(append(object, to.gsplot)))
}