Skip to content

Commit 262bd77

Browse files
author
Jordan S Read
committed
adding changes to ylim and xlim(gsplot) from #246
1 parent b4d97ee commit 262bd77

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

R/access-gsplot.R

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ xlim <- function(object) UseMethod("xlim")
1212
#' @export
1313
xlim.gsplot <- function(object){
1414

15-
lapply(views(object), function(x) x$window$xlim)
15+
names = unname(sapply(views(object), function(x) paste0('side.',x$window$side[1])))
16+
lapply(views(object), function(x) x$window$xlim) %>%
17+
setNames(names)
1618
}
1719

1820
#' ylim for gsplot
@@ -27,7 +29,9 @@ ylim <- function(object) UseMethod("ylim")
2729
#' @export
2830
ylim.gsplot <- function(object){
2931

30-
lapply(views(object), function(x) x$window$ylim)
32+
names = unname(sapply(views(object), function(x) paste0('side.',x$window$side[2])))
33+
lapply(views(object), function(x) x$window$ylim) %>%
34+
setNames(names)
3135
}
3236

3337
#' log for gsplot
97 Bytes
Loading
-1.83 KB
Loading

tests/testthat/test-access_gsplot.R

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,17 @@ test_that("xlim for dual axis", {
2323

2424
})
2525

26+
test_that("xlim for string input", {
27+
28+
usrDef <- gsplot(mar=c(4,4,4,4), xaxs='r', yaxs='r') %>%
29+
points(x=1, y=2, side=c(3,2), legend.name="Points 1", cex=3, xlab='cat') %>%
30+
points(x=3:10,y=4:11, side=c(1,2))
31+
32+
expect_equal(xlim(usrDef)[['side.3']], c(1,1))
33+
expect_equal(xlim(usrDef)[['side.1']], c(3,10))
34+
35+
})
36+
2637
context("test get par for gsplot object")
2738

2839
test_that("par for simple object",{

0 commit comments

Comments
 (0)