-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathsegments.R
More file actions
42 lines (38 loc) · 1.63 KB
/
segments.R
File metadata and controls
42 lines (38 loc) · 1.63 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
#' gsplot segments
#'
#' Creates line segments in the plot. See \code{\link[graphics]{segments}} for more details.
#'
#' @details Additional graphical parameter inputs:
#' \itemize{
#' \item{\code{x0, y0}} {coordinates for the start of the segment}
#' \item{\code{x, y}} {coordinates for the end of the segment}
#' \item{\code{col, lty, lwd}} {parameters describing the color, type, and width of the segment, respectively}
#' }
#'
#' @param object gsplot object
#' @param \dots Further graphical parameters may also be supplied as arguments. See 'Details'.
#'
#' @export
#' @examples
#' gs <- gsplot()
#' gsNew <- points(gs, y=1, x=2, xlim=c(0,NA),ylim=c(0,NA),
#' col="blue", pch=18, legend.name="Points")
#' gsNew <- lines(gsNew, c(3,4,3), c(2,4,6), legend.name="Lines")
#' gsNew <- abline(gsNew, b=1, a=0, legend.name="1:1")
#' gsNew <- legend(gsNew, location="topleft",title="Awesome!")
#' gsNew <- grid(gsNew)
#' gsNew <- segments(gsNew, x0=2, y0=0.75, y1=1.25)
#' gsNew
segments <- function(object, ...) {
override("graphics", "segments", object, ...)
}
segments.gsplot <- function(object, x0, y0, x1=x0, y1=y0, ..., legend.name=NULL, side=c(1,2)){
current_list <- config("segments")
arguments <- append(list(x0=x0, y0=y0, x1=x1, y1=y1), c(...))
indicesToAdd <- !(names(current_list) %in% names(arguments))
arguments <- append(arguments, current_list[indicesToAdd])
object <- append(object, list(segments = list(arguments = arguments,
gs.config=list(legend.name = legend.name,
side = side))))
return(gsplot(object))
}