-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy patharrows.R
More file actions
48 lines (44 loc) · 2.04 KB
/
arrows.R
File metadata and controls
48 lines (44 loc) · 2.04 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
#' gsplot arrows
#'
#' Creates an arrow pointing at a specified plot location. See \code{\link[graphics]{arrows}} for more details.
#'
#' @param object gsplot object
#' @param \dots Further graphical parameters may also be supplied as arguments. See 'Details'.
#'
#' @details Often used with \code{\link{text}} to label a feature on the plot. Additional graphical parameter inputs:
#' \itemize{
#' \item{\code{x0, y0}} {position of the arrow tail}
#' \item{\code{x, y}} {position of the arrow head}
#' \item{\code{col, lty, lwd}} {parameters describing the color, type, and width of the arrow, respectively}
#' }
#'
#' @export
#' @examples
#' gs <- gsplot() %>%
#' points( y=c(3,1,2), x=1:3, xlim=c(0,NA),ylim=c(0,NA),
#' col="blue", pch=18, legend.name="Points", xlab="Index") %>%
#' lines(c(3,4,3), c(2,4,6), legend.name="Lines", ylab="Data") %>%
#' abline(b=1, a=0, legend.name="1:1") %>%
#' legend(location="topleft",title="Awesome!") %>%
#' grid() %>%
#' error_bar(x=1:3, y=c(3,1,2), y.high=c(0.5,0.25,1), y.low=0.1) %>%
#' error_bar(x=1:3, y=c(3,1,2), x.low=.2, x.high=.2, col="red",lwd=3) %>%
#' arrows(x0=0.75, y0=2, x1=1, y1=2.8, lwd=2) %>%
#' title("Graphing Fun") %>%
#' text(.75,1.75,labels="Weird data")
#' gs
arrows <- function(object, ...) {
override("graphics", "arrows", object, ...)
}
arrows.gsplot <- function(object, x0, y0, x1 = x0, y1 = y0, length = 0.25, angle = 30,
..., code = 2, legend.name=NULL, side=c(1,2)){
current_list <- config("arrows")
arguments <- append(list(x0=x0, y0=y0, x1 = x1, y1 = y1, length = length, angle = angle,
code = code), c(...))
indicesToAdd <- !(names(current_list) %in% names(arguments))
arguments <- append(arguments, current_list[indicesToAdd])
object <- append(object, list(arrows = list(arguments = arguments,
gs.config=list(legend.name = legend.name,
side = side))))
return(gsplot(object))
}