Skip to content

Commit 91c9bb5

Browse files
Merge branch 'master' into brokenFormulas
2 parents 2d3e3d0 + 1c5cfe2 commit 91c9bb5

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+1263
-179
lines changed

DESCRIPTION

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
Package: gsplot
22
Type: Package
33
Title: Geological Survey Plotting
4-
Version: 0.7.0
5-
Date: 2016-07-13
4+
Version: 0.7.2
5+
Date: 2017-02-14
66
Authors@R: c( person("Jordan", "Read", role = "aut",
77
email = "[email protected]"),
88
person("Laura", "DeCicco", role = c("aut","cre"),
@@ -26,7 +26,7 @@ Copyright: This software is in the public domain because it contains materials
2626
that originally came from the United States Geological Survey, an agency of
2727
the United States Department of Interior. For more information, see the
2828
official USGS copyright policy at
29-
http://www.usgs.gov/visual-id/credit_usgs.html#copyright
29+
https://www.usgs.gov/visual-id/credit_usgs.html#copyright
3030
Imports:
3131
magrittr,
3232
stats,
@@ -43,4 +43,4 @@ VignetteBuilder: knitr
4343
BuildVignettes: true
4444
LazyLoad: yes
4545
LazyData: yes
46-
RoxygenNote: 6.0.0
46+
RoxygenNote: 6.0.1

NAMESPACE

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,16 @@ export(abline)
1919
export(arrows)
2020
export(as.side_name)
2121
export(axis)
22-
export(bgCol)
23-
export(bgCol.default)
22+
export(background_color)
23+
export(background_color.default)
2424
export(callouts)
2525
export(callouts.default)
26+
export(clear_par)
2627
export(config)
2728
export(curve)
29+
export(date_axis)
30+
export(date_axis.default)
31+
export(date_axis.gsplot)
2832
export(error_bar)
2933
export(error_bar.default)
3034
export(grid)

R/abline.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,8 @@ abline <- function(object, ...) {
3232
abline.gsplot <- function(object, ..., legend.name=NULL, side=c(1,2)){
3333
fun.name <- 'abline'
3434
object <- gather_function_info(object, fun.name, ..., legend.name=legend.name, side=side)
35+
36+
object <- modify_side(object, args = list(...), side=side)
37+
3538
return(object)
3639
}

R/axis.R

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#' gs <- gsplot() %>%
1919
#' points(x=1:5, y=1:5, legend.name="Stuff") %>%
2020
#' lines(2:6, y=2:6, ylim=c(0,10)) %>%
21-
#' bgCol(col="lightgoldenrod") %>%
21+
#' background_color(col="lightgoldenrod") %>%
2222
#' axis(side=c(3,4),labels=FALSE) %>%
2323
#' legend("topright")
2424
#' gs
@@ -91,7 +91,19 @@ axis.gsplot <- function(object, ..., n.minor=0, tcl.minor=0.15, reverse=NULL) {
9191
}
9292

9393
draw_axis <- function(object, side.name){
94-
axis.args <- object[[side.name]][['axis']]
94+
95+
96+
# method isn't made for multiple axis calls
97+
which.axis <- which(names(object[[side.name]]) == 'axis')
98+
if (length(which.axis) > 1){
99+
for (axis.i in which.axis){
100+
tmp <- object
101+
tmp[[side.name]] <- tmp[[side.name]][-which.axis[which.axis %in% axis.i]]
102+
draw_axis(tmp, side.name)
103+
}
104+
}
105+
106+
master axis.args <- object[[side.name]][['axis']]
95107
side.lim <- object[[side.name]][['lim']]
96108

97109
axis.args$at <- get_axTicks(object, as.side(side.name))

R/bgCol.R

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#' gsplot bgCol
1+
#' gsplot background_color
22
#'
33
#' Adds color to the plot background.
44
#'
@@ -10,35 +10,37 @@
1010
#' @examples
1111
#' gs <- gsplot() %>%
1212
#' points(y=c(3,1,2), x=4:6, xlim=c(0,NA),legend.name="Points") %>%
13-
#' bgCol(col="lightgrey") %>%
13+
#' background_color(col="lightgrey") %>%
1414
#' lines( c(3,4,3), c(2,4,6), legend.name="Lines", side=c(3,4)) %>%
1515
#' legend(location="topleft")
1616
#' gs
1717
#'
1818
#' gs <- gsplot() %>%
1919
#' points(1:100, rnorm(100,mean=10000, sd=1000), log="y") %>%
20-
#' bgCol(col="lightgrey")
20+
#' background_color(col="lightgrey")
2121
#' gs
2222
#'
2323
#' gs <- gsplot() %>%
2424
#' points(1:100, rnorm(100,mean=10000, sd=1000), log="y") %>%
25-
#' bgCol() #yaml specifies lightgrey
25+
#' background_color() #yaml specifies lightgrey
2626
#' gs
2727
#'
2828
#' gs <- gsplot() %>%
2929
#' points(1:100, rnorm(100,mean=10000, sd=1000), log="y") %>%
30-
#' bgCol("lightgoldenrod")
30+
#' background_color("lightgoldenrod")
3131
#' gs
32-
bgCol <- function(object, ...) {
33-
override("gsplot", "bgCol", object, ...)
32+
background_color <- function(object, ...) {
33+
override("gsplot", "background_color", object, ...)
3434
}
3535

3636

37-
bgCol.gsplot <- function(object, ...){
37+
background_color.gsplot <- function(object, ..., legend.name=NULL, side=c(1,2)){
3838

39-
to.gsplot <- filter_arguments(fun.name = "bgCol", ...,
40-
custom.config = object[["global"]][["config"]][["config.file"]])$call.args
41-
object$global$bgCol <- append_replace(object$global$bgCol, to.gsplot[[1]])
39+
fun.name='background_color'
40+
41+
arguments <- filter_arguments(fun.name, ..., custom.config = object[["global"]][["config"]][["config.file"]], side=side)
42+
object[["global"]] <- append_replace(object[["global"]], arguments$call.args)
43+
4244
return(object)
4345

4446
}
@@ -50,7 +52,7 @@ bgCol.gsplot <- function(object, ...){
5052
#' Here NULL means color 0.
5153
#' @export
5254
#' @keywords internal
53-
bgCol.default <- function(col=NULL){
55+
background_color.default <- function(col=NULL){
5456

5557
if(par()$xlog){
5658
x1 <- 10^(par("usr")[1])

R/config.R

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
gsconfig <- new.env(parent = emptyenv())
22
gsconfig$original.par <- par(no.readonly = TRUE)
33

4+
#' Clear par
5+
#'
6+
#' Resets par to what it was when gsplot was loaded.
7+
#'
8+
#' @export
9+
clear_par <- function(){
10+
par(gsconfig$original.par)
11+
}
12+
413
#Question...how can I update the user's par?
514

615
#' @title Load gsplot config
@@ -38,20 +47,18 @@ loadConfig = function(filename) {
3847
#'used elsewhere in the application. This will only change the config paremeters while
3948
#'building up the gsplot object, not on print.
4049
#'
41-
#' @param filename string to custom file
50+
#' @param object gsplot object
4251
#'
4352
#' @importFrom graphics plot.xy
4453
#' @importFrom graphics par
4554
#' @importFrom yaml yaml.load_file
4655
#' @importFrom grDevices dev.off
47-
load_temp_config = function(filename) {
48-
49-
graphTemplate <- yaml.load_file(filename)
56+
load_temp_config = function(object){
5057

5158
if(length(all.equal(gsconfig$original.par, par(no.readonly = TRUE))) > 1){
5259
par(gsconfig$original.par)
5360
}
54-
gsconfig$temp.config <- graphTemplate
61+
gsconfig$temp.config <- object[["config"]]
5562
}
5663

5764

R/date_axis.R

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#' gsplot date axis
2+
#'
3+
#' Special axis for date handling, including interval labelling.
4+
#'
5+
#' @param object gsplot object
6+
#' @param \dots Further graphical parameters may also be supplied as arguments. See 'Details'.
7+
#' @details Additional graphical parameter inputs:
8+
#' \itemize{
9+
#' \item{\code{pos.lab}} {where should the label be positioned, centered on the "tick" or "interval".}
10+
#' \item{\code{tick.int}} {interval in which ticks should be placed, alternative to defining at.}
11+
#' \item{\code{snap.to}} {set the limits to coincide with temporal boundaries. Accepts "day", "week", "month", "quarter",
12+
#' "year", "wateryear", "decade".}
13+
#' }
14+
#'
15+
#' @rdname date_axis
16+
#' @export
17+
#' @examples
18+
#' x <- seq(as.Date("2013-01-22"), as.Date("2013-10-02"), "days")
19+
#' y <- rnorm(length(x), 71, 19)
20+
#' gs <- gsplot() %>%
21+
#' points(x, y) %>%
22+
#' date_axis(side=1, pos.lab="interval", tick.int="month", snap.to="year")
23+
#' gs
24+
#'
25+
#' x <- seq(as.POSIXct("1992-03-03 06:00:00"), as.POSIXct("1992-03-08 12:00:00"), "hour")
26+
#' y <- rnorm(length(x), 19, 2)
27+
#' gs <- gsplot() %>%
28+
#' points(x, y) %>%
29+
#' date_axis(side=1, pos.lab="tick", tick.int="day", snap.to="day", format="%D")
30+
#' gs
31+
date_axis <- function(object, ...) {
32+
override("gsplot", "date_axis", object, ...)
33+
}
34+
35+
#' @param side side to place the axis on
36+
#' @param pos.lab where should the label be positioned, centered on the "tick" or "interval".
37+
#' @param at specific location to place ticks
38+
#' @param tick.int interval in which ticks should be placed, alternative to defining at.
39+
#' @param snap.to set the limits to coincide with temporal boundaries. Accepts "day", "week", "month", "quarter",
40+
#' "year", "wateryear", "decade".
41+
#'
42+
#' @rdname date_axis
43+
#' @export
44+
date_axis.gsplot <- function(object, ..., side, pos.lab="tick", at=NULL, tick.int=NULL, snap.to="day") {
45+
if (exists("at") &&!is.null(at) && !is.null(tick.int)) {
46+
warning("cannot specify both at and tick.int, at will be ignored")
47+
}
48+
if (!is.null(tick.int)) {
49+
ticksAt <- lazy({
50+
# calc ticks
51+
limit <- lim(object, side)
52+
# TODO: handle -ly on tick.int
53+
seq(limit[1], limit[2], tick.int)
54+
})
55+
} else if (exists("at") && !is.null(at)) {
56+
ticksAt <- at
57+
} else {
58+
ticksAt <- NULL
59+
}
60+
61+
labelsAt <- lazy({
62+
labels <- NULL
63+
limit <- lim(object, side)
64+
65+
if (is.null(ticksAt)) {
66+
main.ticks <- grid_axTicks(object, side)
67+
} else if (inherits(ticksAt, "lazy")) {
68+
main.ticks <- lazy_eval(ticksAt, data=list(object=object))
69+
} else {
70+
main.ticks <- ticksAt
71+
}
72+
73+
if (pos.lab == "tick") {
74+
labels <- main.ticks
75+
} else if (pos.lab == "interval") {
76+
all.ints <- c(limit[1], main.ticks, limit[2])
77+
for (i in 2:length(all.ints)) {
78+
prev = all.ints[i-1]
79+
curr = all.ints[i]
80+
if (curr != prev) {
81+
label <- prev + (curr-prev) / 2
82+
if (is.null(labels)) labels <- label
83+
else labels <- c(labels, label)
84+
}
85+
}
86+
} else {
87+
stop("pos.lab must be \"tick\" or \"interval\"")
88+
}
89+
return(labels)
90+
})
91+
snapTo <- lazy({
92+
old.lim <- lim(object, side)
93+
# TODO: handle start.on.monday=TRUE use %u instead of %w and offset 1
94+
limit <- switch(snap.to,
95+
"day" = day_period(old.lim),
96+
"week" = week_period(old.lim),
97+
"month" = month_period(old.lim),
98+
"quarter" = quarter_period(old.lim),
99+
"year" = year_period(old.lim),
100+
"wateryear" = wateryear_period(old.lim),
101+
"decade" = decade_period(old.lim),
102+
old.lim # default
103+
)
104+
})
105+
106+
object <- axis(object, ..., side, at=ticksAt, labels=FALSE)
107+
object <- axis(object, ..., side, at=labelsAt, tick=FALSE, append=TRUE)
108+
for (side_name in as.side_name(side)) {
109+
object[[side_name]][["snap.to"]] <- snapTo
110+
}
111+
return(object)
112+
}
113+
114+
#' @rdname date_axis
115+
#' @export
116+
date_axis.default <- function(side, pos.lab="tick", tick.int=NULL, snap.to=NULL, ...) {
117+
warning("date_axis is not implemented for base graphics plots")
118+
return()
119+
}
120+

0 commit comments

Comments
 (0)