Skip to content

Commit 28f9ffb

Browse files
author
Lindsay Carr
authored
Merge pull request #454 from ldecicco-USGS/errorArgs
Error args
2 parents 455298e + 57b2cd8 commit 28f9ffb

File tree

19 files changed

+129
-123
lines changed

19 files changed

+129
-123
lines changed

R/add_to_view.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ add_to_view <- function(object, call.args, side, where){
6464
#' gs <- gsplot() %>%
6565
#' points(x=1:5, y=1:5, xlim=c(0,10), ylim=c(0,10),
6666
#' callouts(labels=c(rep(NA, 4), "oh")),
67-
#' error_bar(y.high=1))
67+
#' error_bar(offset.up=1))
6868
#' gs
6969
#'
7070
#' gsplot:::filter_arguments('points', x=2:6, y=2:6, ylim=c(-1, 11))$call.args

R/arrows.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#' abline(b=1, a=0, legend.name="1:1") %>%
2424
#' legend(location="topleft",title="Awesome!") %>%
2525
#' grid() %>%
26-
#' error_bar(x=1:3, y=c(3,1,2), y.high=c(0.5,0.25,1), y.low=0.1) %>%
27-
#' error_bar(x=1:3, y=c(3,1,2), x.low=.2, x.high=.2, col="red",lwd=3) %>%
26+
#' error_bar(x=1:3, y=c(3,1,2), offset.up=c(0.5,0.25,1), offset.down=0.1) %>%
27+
#' error_bar(x=1:3, y=c(3,1,2), offset.left=.2, offset.right=.2, col="red",lwd=3) %>%
2828
#' arrows(x0=0.75, y0=2, x1=1, y1=2.8, lwd=2) %>%
2929
#' title("Graphing Fun") %>%
3030
#' text(.75,1.75,labels="Weird data")

R/error_bars.R

Lines changed: 66 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88
#' @details Additional graphical parameter inputs:
99
#' \itemize{
1010
#' \item{\code{x, y}} {location of error_bar origin}
11-
#' \item{\code{y.high, y.low}} {the y-value specifying the error above the point (high) and below the point (low)}
12-
#' \item{\code{x.high, x.low}} {the x-value specifying the error above the point (high) and below the point (low)}
11+
#' \item{\code{offset.up, offset.down}} {the y-value specifying the error above the point (high) and below the point (low)}
12+
#' \item{\code{offset.right, offset.left}} {the x-value specifying the error above the point (high) and below the point (low)}
1313
#' \item{\code{epsilon}} {width of the end of the error bar (in inches)}
1414
#' \item{\code{legend.name}} {name that appears in the legend, see \code{\link{legend}} for more legend parameters}
1515
#' }
@@ -24,20 +24,23 @@
2424
#' gsNew <- abline(gsNew, b=1, a=0, legend.name="1:1")
2525
#' gsNew <- legend(gsNew, location = "topleft",title="Awesome!")
2626
#' gsNew <- grid(gsNew)
27-
#' gsNew <- error_bar(gsNew, 1:3, y=c(3,1,2), y.high=c(0.5,0.25,1), y.low=0.1)
28-
#' gsNew <- error_bar(gsNew, x=1:3, y=c(3,1,2), x.low=c(.2,NA,.2), x.high=.2, col="red",lwd=3)
27+
#' gsNew <- error_bar(gsNew, 1:3, y=c(3,1,2),
28+
#' offset.up=c(0.5,0.25,1), offset.down=0.1)
29+
#' gsNew <- error_bar(gsNew, x=1:3, y=c(3,1,2),
30+
#' offset.left=c(.2,NA,.2),
31+
#' offset.right=.2, col="red",lwd=3)
2932
#' gsNew <- title(gsNew, "Graphing Fun")
3033
#' gsNew
3134
#'
3235
#' yData <- rnorm(100,mean=10000, sd=1000)
3336
#' gs <- gsplot() %>%
3437
#' points(1:100, yData, log="y") %>%
35-
#' error_bar(50:60, yData[50:60], y.high=250)
38+
#' error_bar(50:60, yData[50:60], offset.up=250)
3639
#' gs
3740
#'
3841
#' gs <- gsplot() %>%
3942
#' points(1:10, 1:10) %>%
40-
#' error_bar(5, 5, y.high=1, col="green")
43+
#' error_bar(5, 5, offset.up=1, col="green")
4144
#' gs
4245
error_bar <- function(object, ...) {
4346
override("gsplot", "error_bar", object, ...)
@@ -67,101 +70,101 @@ error_bar.gsplot <- function(object, ..., legend.name=NULL, side=c(1,2)){
6770
#'
6871
#' @param x location in x
6972
#' @param y location in y
70-
#' @param y.high offset up
71-
#' @param y.low offset down
72-
#' @param x.high offset right
73-
#' @param x.low offset left
73+
#' @param offset.up offset up
74+
#' @param offset.down offset down
75+
#' @param offset.right offset right
76+
#' @param offset.left offset left
7477
#' @param epsilon width of bar in relative units
7578
#' @param \dots additional arguments passed to \code{\link[graphics]{arrows}}
7679
#' @export
7780
#' @examples
7881
#' plot(1:10, 1:10)
79-
#' error_bar(5, 5, y.high=1, col="green")
80-
error_bar.default <- function(x, y, y.high=0, y.low=0, x.high=0, x.low=0, epsilon=0.1, ...){
82+
#' error_bar(5, 5, offset.up=1, col="green")
83+
error_bar.default <- function(x, y, offset.up=0, offset.down=0, offset.right=0, offset.left=0, epsilon=0.1, ...){
8184

82-
data.list <- calculate_error_bars(x=x,y=y,y.high=y.high,y.low=y.low,x.high=x.high, x.low=x.low, epsilon=epsilon)
85+
data.list <- calculate_error_bars(x=x,y=y,offset.up=offset.up,offset.down=offset.down,offset.right=offset.right, offset.left=offset.left, epsilon=epsilon)
8386

84-
if(length(data.list[["y.low"]]) > 1){
85-
graphics::arrows(x0=data.list[["y.low"]]$x0,
86-
y0=data.list[["y.low"]]$y0,
87-
x1=data.list[["y.low"]]$x1,
88-
y1=data.list[["y.low"]]$y1,
89-
length=data.list[["y.low"]]$length, angle=90, ...)
87+
if(length(data.list[["offset.down"]]) > 1){
88+
graphics::arrows(x0=data.list[["offset.down"]]$x0,
89+
y0=data.list[["offset.down"]]$y0,
90+
x1=data.list[["offset.down"]]$x1,
91+
y1=data.list[["offset.down"]]$y1,
92+
length=data.list[["offset.down"]]$length, angle=90, ...)
9093
}
9194

92-
if(length(data.list[["y.high"]]) > 1){
93-
graphics::arrows(x0=data.list[["y.high"]]$x0,
94-
y0=data.list[["y.high"]]$y0,
95-
x1=data.list[["y.high"]]$x1,
96-
y1=data.list[["y.high"]]$y1,
97-
length=data.list[["y.high"]]$length, angle=90, ...)
95+
if(length(data.list[["offset.up"]]) > 1){
96+
graphics::arrows(x0=data.list[["offset.up"]]$x0,
97+
y0=data.list[["offset.up"]]$y0,
98+
x1=data.list[["offset.up"]]$x1,
99+
y1=data.list[["offset.up"]]$y1,
100+
length=data.list[["offset.up"]]$length, angle=90, ...)
98101
}
99102

100-
if(length(data.list[["x.low"]]) > 1){
101-
graphics::arrows(x0=data.list[["x.low"]]$x0,
102-
y0=data.list[["x.low"]]$y0,
103-
x1=data.list[["x.low"]]$x1,
104-
y1=data.list[["x.low"]]$y1,
105-
length=data.list[["x.low"]]$length, angle=90, ...)
103+
if(length(data.list[["offset.left"]]) > 1){
104+
graphics::arrows(x0=data.list[["offset.left"]]$x0,
105+
y0=data.list[["offset.left"]]$y0,
106+
x1=data.list[["offset.left"]]$x1,
107+
y1=data.list[["offset.left"]]$y1,
108+
length=data.list[["offset.left"]]$length, angle=90, ...)
106109
}
107110

108-
if(length(data.list[["x.high"]]) > 1){
109-
graphics::arrows(x0=data.list[["x.high"]]$x0,
110-
y0=data.list[["x.high"]]$y0,
111-
x1=data.list[["x.high"]]$x1,
112-
y1=data.list[["x.high"]]$y1,
113-
length=data.list[["x.high"]]$length, angle=90, ...)
111+
if(length(data.list[["offset.right"]]) > 1){
112+
graphics::arrows(x0=data.list[["offset.right"]]$x0,
113+
y0=data.list[["offset.right"]]$y0,
114+
x1=data.list[["offset.right"]]$x1,
115+
y1=data.list[["offset.right"]]$y1,
116+
length=data.list[["offset.right"]]$length, angle=90, ...)
114117
}
115118

116119
return()
117120
}
118121

119-
calculate_error_bars <- function(x, y, y.high=0, y.low=0, x.high=0, x.low=0, epsilon=0.1, ...){
120-
y.high[is.na(y.high)] <- 0
121-
y.low[is.na(y.low)] <- 0
122-
x.high[is.na(x.high)] <- 0
123-
x.low[is.na(x.low)] <- 0
122+
calculate_error_bars <- function(x, y, offset.up=0, offset.down=0, offset.right=0, offset.left=0, epsilon=0.1, ...){
123+
offset.up[is.na(offset.up)] <- 0
124+
offset.down[is.na(offset.down)] <- 0
125+
offset.right[is.na(offset.right)] <- 0
126+
offset.left[is.na(offset.left)] <- 0
124127

125128
data.list <- rep(list(list()), 4)
126-
names(data.list) <- c("y.low","y.high","x.low","x.high")
129+
names(data.list) <- c("offset.down","offset.up","offset.left","offset.right")
127130

128-
if(!all(y.low == 0)){
129-
y.low.coord <- y-y.low
130-
errorIndex <- (y-y.low.coord) != 0
131-
y.low.coord <- y.low.coord[errorIndex]
131+
if(!all(offset.down == 0)){
132+
offset.down.coord <- y-offset.down
133+
errorIndex <- (y-offset.down.coord) != 0
134+
offset.down.coord <- offset.down.coord[errorIndex]
132135
y.error <- y[errorIndex]
133136
x.error <- x[errorIndex]
134-
data.list[["y.low"]] <- list(x0=x.error, y0=y.error, x1=x.error, y1=y.low.coord,
137+
data.list[["offset.down"]] <- list(x0=x.error, y0=y.error, x1=x.error, y1=offset.down.coord,
135138
length=epsilon, angle=90)
136139
}
137140

138-
if(!all(y.high == 0)){
139-
y.high.coord <- y+y.high
140-
errorIndex <- (y-y.high.coord) != 0
141-
y.high.coord <- y.high.coord[errorIndex]
141+
if(!all(offset.up == 0)){
142+
offset.up.coord <- y+offset.up
143+
errorIndex <- (y-offset.up.coord) != 0
144+
offset.up.coord <- offset.up.coord[errorIndex]
142145
y.error <- y[errorIndex]
143146
x.error <- x[errorIndex]
144-
data.list[["y.high"]] <- list(x0=x.error, y0=y.error, x1=x.error, y1=y.high.coord, length=epsilon,
147+
data.list[["offset.up"]] <- list(x0=x.error, y0=y.error, x1=x.error, y1=offset.up.coord, length=epsilon,
145148
angle=90)
146149
}
147150

148-
if(!all(x.low == 0)){
149-
x.low.coord <- x-x.low
150-
errorIndex <- (x-x.low.coord) != 0
151-
x.low.coord <- x.low.coord[errorIndex]
151+
if(!all(offset.left == 0)){
152+
offset.left.coord <- x-offset.left
153+
errorIndex <- (x-offset.left.coord) != 0
154+
offset.left.coord <- offset.left.coord[errorIndex]
152155
x.error <- x[errorIndex]
153156
y.error <- y[errorIndex]
154-
data.list[["x.low"]] <- list(x0=x.error, y0=y.error, x1=x.low.coord, y1=y.error, length=epsilon,
157+
data.list[["offset.left"]] <- list(x0=x.error, y0=y.error, x1=offset.left.coord, y1=y.error, length=epsilon,
155158
angle=90)
156159
}
157160

158-
if(!all(x.high == 0)){
159-
x.high.coord <- x+x.high
160-
errorIndex <- (x-x.high.coord) != 0
161-
x.high.coord <- x.high.coord[errorIndex]
161+
if(!all(offset.right == 0)){
162+
offset.right.coord <- x+offset.right
163+
errorIndex <- (x-offset.right.coord) != 0
164+
offset.right.coord <- offset.right.coord[errorIndex]
162165
x.error <- x[errorIndex]
163166
y.error <- y[errorIndex]
164-
data.list[["x.high"]] <- list(x0=x.error, y0=y.error, x1=x.high.coord, y1=y.error, length=epsilon,
167+
data.list[["offset.right"]] <- list(x0=x.error, y0=y.error, x1=offset.right.coord, y1=y.error, length=epsilon,
165168
angle=90)
166169
}
167170

R/points.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
#' gs <- gsplot() %>%
2929
#' points(x=1:5, y=1:5, xlim=c(0,10), ylim=c(0,10),
3030
#' callouts(labels=c(rep(NA, 4), "oh")),
31-
#' error_bar(y.high=1))
31+
#' error_bar(offset.up=1))
3232
#' gs
3333
#'
3434
#' gs2 <- gsplot() %>%

R/text.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
#' abline(b=1, a=0, legend.name="1:1") %>%
3232
#' legend(location="topleft",title="Awesome!") %>%
3333
#' grid() %>%
34-
#' error_bar(x=1:3, y=c(3,1,2), y.high=c(0.5,0.25,1), y.low=0.1) %>%
35-
#' error_bar(x=1:3, y=c(3,1,2), x.low=.2, x.high=.2, col="red",lwd=3) %>%
34+
#' error_bar(x=1:3, y=c(3,1,2), offset.up=c(0.5,0.25,1), offset.down=0.1) %>%
35+
#' error_bar(x=1:3, y=c(3,1,2), offset.left=.2, x.high=.2, col="red",lwd=3) %>%
3636
#' arrows(x0=c(0.75, 1.75), y0=c(2,2.5), x1=c(1,2), y1=c(2.8,1.4), lwd=2) %>%
3737
#' text(x=c(0.75, 1.75), y=c(1.75, 2.8),labels=c("Weird data", "Other Data")) %>%
3838
#' title("Graphing Fun")

README.Rmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ arrows(x0 = 1:7, x1 = 1:7,
150150
```{r message=FALSE, warning=FALSE}
151151
errorbarplot <- gsplot() %>%
152152
points(1:7, 1:7) %>%
153-
error_bar(x = 1:7, y = 1:7, y.high = 1, y.low = 1)
153+
error_bar(x = 1:7, y = 1:7, offset.up = 1, offset.down = 1)
154154
errorbarplot
155155
```
156156

@@ -220,7 +220,7 @@ text(x = 1.25:5.25, y = 1.25:5.25,
220220
```{r }
221221
embedplot <- gsplot() %>%
222222
points(1:5, 1:5,
223-
error_bar(y.high = 1, y.low = 0.5),
223+
error_bar(offset.up = 1, offset.down = 0.5),
224224
callouts(labels = paste("pt", 1:5)))
225225
embedplot
226226
```
@@ -278,8 +278,8 @@ points(as.Date("2011-01-15"),2.5, col="blue", pch=20)
278278
demoPlot <- gsplot() %>%
279279
points(y=c(3,1,2), x=1:3, xlim=c(0,NA),ylim=c(0,NA),
280280
col="blue", pch=18, legend.name="Points", xlab="Index",
281-
error_bar(y.high = c(0.5,0.25,1), y.low = 0.1,
282-
x.low=0.2, x.high=0.2, col="red", lwd=2)) %>%
281+
error_bar(offset.up = c(0.5,0.25,1), offset.down = 0.1,
282+
offset.left=0.2, offset.right=0.2, col="red", lwd=2)) %>%
283283
lines(c(3,4,3), c(2,4,6), legend.name="Lines", ylab=expression(paste("Data [ft"^"3","/s]"))) %>%
284284
abline(b=1, a=0, legend.name="1:1") %>%
285285
axis(side=c(3,4), labels=FALSE) %>%

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ arrows(x0 = 1:7, x1 = 1:7,
179179
``` r
180180
errorbarplot <- gsplot() %>%
181181
points(1:7, 1:7) %>%
182-
error_bar(x = 1:7, y = 1:7, y.high = 1, y.low = 1)
182+
error_bar(x = 1:7, y = 1:7, offset.up = 1, offset.down = 1)
183183
errorbarplot
184184
```
185185

@@ -255,7 +255,7 @@ text(x = 1.25:5.25, y = 1.25:5.25,
255255
``` r
256256
embedplot <- gsplot() %>%
257257
points(1:5, 1:5,
258-
error_bar(y.high = 1, y.low = 0.5),
258+
error_bar(offset.up = 1, offset.down = 0.5),
259259
callouts(labels = paste("pt", 1:5)))
260260
embedplot
261261
```
@@ -322,8 +322,8 @@ Improved workflow examples
322322
demoPlot <- gsplot() %>%
323323
points(y=c(3,1,2), x=1:3, xlim=c(0,NA),ylim=c(0,NA),
324324
col="blue", pch=18, legend.name="Points", xlab="Index",
325-
error_bar(y.high = c(0.5,0.25,1), y.low = 0.1,
326-
x.low=0.2, x.high=0.2, col="red", lwd=2)) %>%
325+
error_bar(offset.up = c(0.5,0.25,1), offset.down = 0.1,
326+
offset.left=0.2, offset.right=0.2, col="red", lwd=2)) %>%
327327
lines(c(3,4,3), c(2,4,6), legend.name="Lines", ylab=expression(paste("Data [ft"^"3","/s]"))) %>%
328328
abline(b=1, a=0, legend.name="1:1") %>%
329329
axis(side=c(3,4), labels=FALSE) %>%

inst/doc/gsplotIntro.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ demoPlot <- gsplot() %>%
1010
abline(b=1, a=0, legend.name="1:1") %>%
1111
legend(location="topleft",title="Awesome!") %>%
1212
grid() %>%
13-
error_bar(x=1:3, y=c(3,1,2), y.high=c(0.5,0.25,1), y.low=0.1) %>%
14-
error_bar(x=1:3, y=c(3,1,2), x.low=.2, x.high=.2, col="red",lwd=3) %>%
13+
error_bar(x=1:3, y=c(3,1,2), offset.up=c(0.5,0.25,1), offset.down=0.1) %>%
14+
error_bar(x=1:3, y=c(3,1,2), offset.left=.2, offset.right=.2, col="red",lwd=3) %>%
1515
callouts(x=1, y=2.8, lwd=2, angle=250, labels="Weird data") %>%
1616
title("Graphing Fun")
1717
demoPlot

inst/doc/gsplotIntro.Rmd

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ demoPlot <- gsplot() %>%
2525
abline(b=1, a=0, legend.name="1:1") %>%
2626
legend(location="topleft",title="Awesome!") %>%
2727
grid() %>%
28-
error_bar(x=1:3, y=c(3,1,2), y.high=c(0.5,0.25,1), y.low=0.1) %>%
29-
error_bar(x=1:3, y=c(3,1,2), x.low=.2, x.high=.2, col="red",lwd=3) %>%
28+
error_bar(x=1:3, y=c(3,1,2), offset.up=c(0.5,0.25,1), offset.down=0.1) %>%
29+
error_bar(x=1:3, y=c(3,1,2), offset.left=.2, offset.right=.2, col="red",lwd=3) %>%
3030
callouts(x=1, y=2.8, lwd=2, angle=250, labels="Weird data") %>%
3131
title("Graphing Fun")
3232
demoPlot
@@ -35,7 +35,7 @@ demoPlot
3535

3636
## Overview
3737

38-
`gsplot` uses similar plotting graphics to R base graphics, but allows users to execute them in a more intuitive manner. Additionally, as the complexity of the plot features increase, `gpslot` code is simplistic compared to that of base graphics. `gsplot` also includes features not present in base graphics that are useful when working with USGS data, such as `callouts` (combines `segments` and `text` into a single call), `error_bar` (allows an error to be given as `y.high`, `y.low`, `x.high`, and `x.low` and automatically builds an error bar), and the argument `legend.name` (an argument within `points`, `lines`, etc. which does not require colors, linetypes, and other par information to be redefined within the `legend` call).
38+
`gsplot` uses similar plotting graphics to R base graphics, but allows users to execute them in a more intuitive manner. Additionally, as the complexity of the plot features increase, `gpslot` code is simplistic compared to that of base graphics. `gsplot` also includes features not present in base graphics that are useful when working with USGS data, such as `callouts` (combines `segments` and `text` into a single call), `error_bar` (allows an error to be given as `offset.up`, `offset.down`, `offset.right`, and `offset.left` and automatically builds an error bar), and the argument `legend.name` (an argument within `points`, `lines`, etc. which does not require colors, linetypes, and other par information to be redefined within the `legend` call).
3939

4040
## Data manipulation
4141

0 commit comments

Comments
 (0)