Skip to content

Commit f6601bb

Browse files
author
Lindsay Carr
authored
Merge pull request #396 from lindsaycarr/master
draw_axis handling different data types
2 parents 40dbb30 + 23f522c commit f6601bb

File tree

9 files changed

+63
-30
lines changed

9 files changed

+63
-30
lines changed

R/axis.R

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,18 @@ axis.gsplot <- function(object, ..., n.minor=0, tcl.minor=0.15, reverse=NULL) {
8888

8989
}
9090

91-
draw_axis <- function(axis.args){
91+
draw_axis <- function(object, side.name){
92+
axis.args <- object[[side.name]][['axis']]
93+
side.lim <- object[[side.name]][['lim']]
94+
95+
axis.args$at <- get_axTicks(object, as.side(side.name))
9296

9397
# need a cleaner way to extract the non-axis args (such as n.minor and tcl.minor)
9498

9599
if(!exists('n.minor',axis.args) || axis.args$n.minor == 0){
96100
axis.args$n.minor <- NULL
97101
axis.args$tcl.minor <- NULL
98-
axis(axis.args)
102+
do.call('Axis', axis.args)
99103
} else {
100104
n.minor <- axis.args$n.minor + 1
101105

@@ -108,7 +112,7 @@ draw_axis <- function(axis.args){
108112
axis.args$n.minor <- NULL
109113
axis.args$tcl.minor <- NULL
110114

111-
axis(axis.args)
115+
do.call('Axis', axis.args)
112116

113117

114118

@@ -144,6 +148,6 @@ draw_axis <- function(axis.args){
144148
axis.args$at <- newAT
145149
axis.args$labels <- FALSE
146150
axis.args$tcl <- tcl
147-
axis(axis.args)
151+
do.call('Axis', axis.args)
148152
}
149153
}

R/grid.R

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,15 @@ draw_custom_grid <- function(object, view.name){
6161

6262
if (is.null(grid.args$nx)){
6363
x.side <- as.x_side_name(view.name)
64-
at <- axis_axTicks(object, as.side(x.side))
65-
if (is.null(at)){
66-
at <- grid_axTicks(object, as.side(x.side))
67-
}
64+
at <- get_axTicks(object, as.side(x.side))
6865
abline(v=at, remove_field(grid.args, c("equilogs", "nx", "ny")))
6966
} else {
7067
grid(ny=NA, remove_field(grid.args, "ny"))
7168
}
7269

7370
if (is.null(grid.args$ny)){
7471
y.side <- as.y_side_name(view.name)
75-
at <- axis_axTicks(object, as.side(y.side))
76-
if (is.null(at)){
77-
at <- grid_axTicks(object, as.side(y.side))
78-
}
72+
at <- get_axTicks(object, as.side(y.side))
7973
abline(h=at, remove_field(grid.args, c("equilogs", "nx", "ny")))
8074
} else {
8175
grid(nx=NA, remove_field(grid.args, "nx"))
@@ -102,8 +96,7 @@ grid_axTicks <- function(object, side){
10296
if(is.numeric(lim)){
10397
at <- axTicks(side)
10498
} else{
105-
fun <- getFromNamespace(paste0('axis.',class(lim)[1L]),'graphics')
106-
at <- fun(side, x = lim, lwd=0, lwd.ticks=0, labels = FALSE)
99+
at <- Axis(side = side, x = pretty(lim), lwd=0, lwd.ticks=0, labels = FALSE)
107100
}
108101
return(at)
109102
}
@@ -114,8 +107,21 @@ grid_axTicks <- function(object, side){
114107
#' @param side a numeric side
115108
#' @return a series of ticks as a vector, or NULL if they weren't specified
116109
#' @keywords internal
117-
axis_axTicks <- function(object, side){
110+
usr_axTicks <- function(object, side){
118111
i <- grep(as.side_name(side), names(object))
119112
usr.at <- object[[i]][['axis']][['at']]
120113
return(usr.at)
121114
}
115+
116+
#' get the axes ticks for grid or axes
117+
#'
118+
#' @param object a gsplot object
119+
#' @param side a numeric side
120+
#' @return a series of ticks as a vector, or NULL if they weren't specified
121+
#' @keywords internal
122+
get_axTicks <- function(object, side){
123+
at <- usr_axTicks(object, side)
124+
if (is.null(at)){
125+
at <- grid_axTicks(object, side)
126+
}
127+
}

R/print.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ print.gsplot <- function(x, ...){
7171
old.par <- par(x[[side.name]]$par)
7272
set_frame(views, side)
7373
if(x[[side.name]][['axes']] | x[[side.name]][['usr.axes']]){
74-
draw_axis(x[[side.name]][['axis']])
74+
draw_axis(x, side.name)
7575
}
7676

7777
if(par('ann')){

README.Rmd

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,11 +225,12 @@ embedplot
225225
If you need to use a feature that `gsplot` has yet to implement, you can always start with `gsplot` and add on using base R. The reverse is (starting with base and then using `gsplot`) is not supported.
226226

227227
```{r message=FALSE, warning=FALSE}
228+
date_vector <- seq(as.Date("2010-10-01"), as.Date("2011-09-30"), by="months")
228229
gs <- gsplot() %>%
229-
points(1,2)
230+
points(date_vector, 1:12)
230231
gs
231232
232-
points(1.2,2.5)
233+
points(as.Date("2010-11-15"),2.5)
233234
```
234235

235236
##Improved workflow examples

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,11 +265,12 @@ embedplot
265265
If you need to use a feature that `gsplot` has yet to implement, you can always start with `gsplot` and add on using base R. The reverse is (starting with base and then using `gsplot`) is not supported.
266266

267267
``` r
268+
date_vector <- seq(as.Date("2010-10-01"), as.Date("2011-09-30"), by="months")
268269
gs <- gsplot() %>%
269-
points(1,2)
270+
points(date_vector, 1:12)
270271
gs
271272

272-
points(1.2,2.5)
273+
points(as.Date("2010-11-15"),2.5)
273274
```
274275

275276
![](README_files/figure-markdown_github/unnamed-chunk-16-1.png)
879 Bytes
Loading

inst/doc/gsplotIntro.html

Lines changed: 7 additions & 7 deletions
Large diffs are not rendered by default.

man/get_axTicks.Rd

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)