Skip to content

Commit 5f3161d

Browse files
author
Jordan S Read
committed
Merge branch 'master' of github.com:USGS-R/gsplot
2 parents 76b7daf + 28f9ffb commit 5f3161d

File tree

167 files changed

+1659
-386
lines changed

Some content is hidden

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

167 files changed

+1659
-386
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.3
5+
Date: 2017-02-16
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: 5.0.1
46+
RoxygenNote: 6.0.1

NAMESPACE

Lines changed: 12 additions & 3 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)
@@ -43,9 +47,13 @@ export(rect)
4347
export(segments)
4448
export(symbols)
4549
export(text)
50+
export(theme.hadley)
51+
export(theme.packers)
4652
export(title)
4753
export(view)
4854
export(view_info)
55+
export(whatDate)
56+
export(whatVersion)
4957
export(xlab)
5058
export(xlim)
5159
export(ylab)
@@ -67,13 +75,14 @@ importFrom(lazyeval,lazy_dots)
6775
importFrom(lazyeval,lazy_eval)
6876
importFrom(magrittr,"%>%")
6977
importFrom(methods,existsFunction)
78+
importFrom(methods,getPackageName)
7079
importFrom(stats,median)
7180
importFrom(stats,na.omit)
7281
importFrom(stats,setNames)
7382
importFrom(utils,find)
7483
importFrom(utils,getFromNamespace)
7584
importFrom(utils,getS3method)
76-
importFrom(utils,head)
85+
importFrom(utils,packageDescription)
7786
importFrom(utils,packageName)
7887
importFrom(utils,tail)
7988
importFrom(yaml,yaml.load_file)

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/access-gsplot.R

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,4 +258,28 @@ view_info <- function(object){
258258
viewInfo$y.side.defined.by.user <- viewInfo$y %in% defined.sides
259259

260260
return(viewInfo)
261-
}
261+
}
262+
263+
#' Get gsplot object creation date.
264+
#'
265+
#' Get the date that this gsplot object was originally created.
266+
#'
267+
#' @param object a gsplot object
268+
#' @return The date the gsplot object was created.
269+
#' @export
270+
whatDate <- function(object){
271+
date_created <- object$metadata$created
272+
return(date_created)
273+
}
274+
275+
#' Get gsplot version used.
276+
#'
277+
#' Get the version number that was used to create this gsplot object.
278+
#'
279+
#' @param object a gsplot object
280+
#' @return The gsplot version number.
281+
#' @export
282+
whatVersion <- function(object){
283+
version_created <- object$metadata$gsplot.version
284+
return(version_created)
285+
}

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/axis.R

Lines changed: 13 additions & 21 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
@@ -64,7 +64,6 @@ axis <- function(object, ...) {
6464
override("graphics", "axis", object, ...)
6565
}
6666

67-
#' @importFrom utils head
6867
axis.gsplot <- function(object, ..., n.minor=0, tcl.minor=0.15, reverse=NULL, append=FALSE) {
6968

7069
fun.name <- "axis"
@@ -79,25 +78,14 @@ axis.gsplot <- function(object, ..., n.minor=0, tcl.minor=0.15, reverse=NULL, ap
7978

8079
for(side in sides){
8180
# append the side and give it defaults if it doesn't exist
82-
83-
object <- modify_side(object, args = list(), side=side)
84-
which.axis <- which(names(object[[as.side_name(side)]])== 'axis')
85-
if (append){
86-
last.axis <- tail(which.axis, 1) # get the last one
87-
object[[as.side_name(side)]] <- append(object[[as.side_name(side)]],
88-
list('axis' = set_args('axis', side=side, package='graphics')),
89-
after = last.axis)
90-
object[[as.side_name(side)]][[last.axis+1]] <- append_replace(object[[as.side_name(side)]][[last.axis+1]], user_args[[fun.name]])
81+
if(append){
82+
9183
} else {
92-
# remove
93-
if (length(which.axis) > 1){
94-
# remove all axis functions other than the first one
95-
object[[as.side_name(side)]] <- object[[as.side_name(side)]][-which.axis[!which.axis %in% head(which.axis, 1)]]
96-
}
97-
object[[as.side_name(side)]][['axis']] <- append_replace(object[[as.side_name(side)]][['axis']], user_args[[fun.name]])
84+
object <- modify_side(object, args = list(), side=side)
9885
}
99-
object[[as.side_name(side)]][['usr.axes']] <- TRUE
10086

87+
object[[as.side_name(side)]][['usr.axes']] <- TRUE
88+
object[[as.side_name(side)]][['axis']] <- append_replace(object[[as.side_name(side)]][['axis']], user_args[[fun.name]])
10189
if (!is.null(reverse)){
10290
object[[as.side_name(side)]][['reverse']] <- reverse
10391
}
@@ -108,6 +96,8 @@ axis.gsplot <- function(object, ..., n.minor=0, tcl.minor=0.15, reverse=NULL, ap
10896
}
10997

11098
draw_axis <- function(object, side.name){
99+
100+
111101
# method isn't made for multiple axis calls
112102
which.axis <- which(names(object[[side.name]]) == 'axis')
113103
if (length(which.axis) > 1){
@@ -116,11 +106,11 @@ draw_axis <- function(object, side.name){
116106
tmp[[side.name]] <- tmp[[side.name]][-which.axis[which.axis %in% axis.i]]
117107
draw_axis(tmp, side.name)
118108
}
119-
120109
}
110+
121111
axis.args <- object[[side.name]][['axis']]
122112
side.lim <- object[[side.name]][['lim']]
123-
113+
124114
axis.args$at <- get_axTicks(object, as.side(side.name))
125115

126116
# need a cleaner way to extract the non-axis args (such as n.minor and tcl.minor)
@@ -141,7 +131,9 @@ draw_axis <- function(object, side.name){
141131
axis.args$n.minor <- NULL
142132
axis.args$tcl.minor <- NULL
143133

144-
do.call('Axis', axis.args)
134+
do.call('Axis', axis.args)
135+
136+
145137

146138
# Minor axis:
147139

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

0 commit comments

Comments
 (0)