-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathpoints.R
More file actions
63 lines (61 loc) · 2.43 KB
/
points.R
File metadata and controls
63 lines (61 loc) · 2.43 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
56
57
58
59
60
61
62
63
#' gsplot points
#'
#' Creates points on gsplot. See \code{\link[graphics]{points}} for more details.
#'
#' @details Additional graphical parameter inputs:
#' \itemize{
#' \item{\code{x}} {vector indicating the x-coordinate(s) of the plot point(s)}
#' \item{\code{y}} {vector indicating the y-coordinate(s) of the plot point(s)}
#' \item{\code{xlim}} {vector containing the lower and upper limit for the x-axis}
#' \item{\code{ylim}} {vector containing the lower and upper limit for the y-axis}
#' \item{\code{col, pch}} {parameters describing the color and type of point, respectively}
#' \item{\code{legend.name}} {name that appears in the legend, see \code{\link{legend}}}
#' \item{\code{error_bar}} {add error bars to the defined points, see \code{\link{error_bar}}
#' for arguments, must add arguments as a list}
#' \item{\code{callouts}} {add callouts and text to the defined points, see \code{\link{callouts}}
#' for arguments, must add arguments as a list}
#' }
#'
#' @param object gsplot object
#' @param \dots Further graphical parameters may also be supplied as arguments. See 'Details'.
#'
#' @examples
#' gs <- gsplot()
#' gsNew <- points(gs, y=1, x=2, col="blue", pch=18,frame.plot=FALSE)
#' gsNew <- points(gsNew, c(3,4,3), c(2,4,6), ylim=c(0,10))
#' gsNew
#'
#' gs <- gsplot() %>%
#' points(x=1:5, y=1:5, xlim=c(0,10), ylim=c(0,10),
#' callouts=list(labels=c(rep(NA, 4), "oh")),
#' error_bar=list(y.high=1))
#' gs
#'
#' gs2 <- gsplot() %>%
#' points(1:5, c(1,10,100,1000,10000), log="y", las=1) %>%
#' axis(side=c(2,4), labels=FALSE, n.minor=4)
#'
#' gs2
#'
#' gs <- points(gsplot(), c(0,3), c(2,4), callouts(labels=c('dogs','cats')))
#' gs
#' @importFrom lazyeval lazy_dots lazy_eval
#' @export
points <- function(object, ...) {
override("graphics", "points", object, ...)
}
points.gsplot <- function(object, ..., legend.name=NULL, side=c(1,2)){
fun.name <- "points"
dots = separate_args(...)
args = dots$args
e.fun = dots$e.fun
arguments = set_args(fun.name, lazy_eval(args))
to.gsplot <- list(list(arguments = arguments, gs.config=list(legend.name = legend.name, side = side))) %>%
setNames(fun.name)
object <- gsplot(append(object, to.gsplot)) # append initial call
if (!is.null(e.fun)){
embed.args = set_inherited_args(e.fun, arguments, dots$e.args)
object <- do.call(e.fun, append(list(object=object), embed.args))
}
return(object)
}