Skip to content

Commit d5edefe

Browse files
author
Jordan S Read
committed
using sides arg on xlim and ylim too
1 parent 93aefac commit d5edefe

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

R/access-gsplot.R

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,42 @@
55
#' get the xlim for views in gsplot object
66
#'
77
#' @param object a gsplot object
8+
#' @param side which side(s) to use
89
#'
910
#' @export
10-
xlim <- function(object) UseMethod("xlim")
11+
xlim <- function(object, side) UseMethod("xlim")
1112

1213
#' @export
13-
xlim.gsplot <- function(object){
14+
xlim.gsplot <- function(object, side=NULL){
1415

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)
16+
if (!is.null(side))
17+
views <- object[views_with_side(views(object), side)]
18+
else
19+
views <- views(object)
20+
names = unname(sapply(views, function(x) paste0('side.',x$window$side[1])))
21+
unique(lapply(views, function(x) x$window$xlim)) %>%
22+
setNames(unique(names))
1823
}
1924

2025
#' ylim for gsplot
2126
#'
2227
#' get the ylim for views in gsplot object
2328
#'
2429
#' @param object a gsplot object
30+
#' @param side which side(s) to use
2531
#'
2632
#' @export
27-
ylim <- function(object) UseMethod("ylim")
33+
ylim <- function(object, side) UseMethod("ylim")
2834

2935
#' @export
30-
ylim.gsplot <- function(object){
31-
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)
36+
ylim.gsplot <- function(object, side=NULL){
37+
if (!is.null(side))
38+
views <- object[views_with_side(views(object), side)]
39+
else
40+
views <- views(object)
41+
names = unname(sapply(views, function(x) paste0('side.',x$window$side[2])))
42+
unique(lapply(views, function(x) x$window$ylim)) %>%
43+
setNames(unique(names))
3544
}
3645

3746
#' log for gsplot

man/xlim.Rd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
\alias{xlim}
55
\title{xlim for gsplot}
66
\usage{
7-
xlim(object)
7+
xlim(object, side)
88
}
99
\arguments{
1010
\item{object}{a gsplot object}
11+
12+
\item{side}{which side(s) to use}
1113
}
1214
\description{
1315
get the xlim for views in gsplot object

man/ylim.Rd

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
\alias{ylim}
55
\title{ylim for gsplot}
66
\usage{
7-
ylim(object)
7+
ylim(object, side)
88
}
99
\arguments{
1010
\item{object}{a gsplot object}
11+
12+
\item{side}{which side(s) to use}
1113
}
1214
\description{
1315
get the ylim for views in gsplot object

tests/testthat/test-access_gsplot.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ test_that("xlim for string input", {
3030
points(x=3:10,y=4:11, side=c(1,2))
3131

3232
expect_equal(xlim(usrDef)[['side.3']], c(1,1))
33-
expect_equal(xlim(usrDef)[['side.1']], c(3,10))
33+
expect_equal(xlim(usrDef, side = 3)[[1]], c(1,1))
34+
expect_equal(xlim(usrDef, side = 1)[[1]], c(3,10))
3435

3536
})
3637

0 commit comments

Comments
 (0)