Skip to content

Commit feb7a58

Browse files
committed
key field tracks subplot counter, not plot; add a test for subplot with group/[x-y]axis specification
1 parent 12c51d2 commit feb7a58

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

R/subplots.R

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ subplot <- function(..., nrows = 1, which_layout = "merge", margin = 0.02) {
7979
# (I don't think it makes sense to support partial specification of domains)
8080
if (all(is.na(with(p_info, c(xstart, xend, ystart, yend))))) {
8181
doms <- get_domains(max(p_info$key), nrows, margin)
82-
doms$plot <- as.character(seq_len(nrow(doms)))
82+
doms$key <- as.character(seq_len(nrow(doms)))
8383
p_info <- p_info[!names(p_info) %in% c("xstart", "xend", "ystart", "yend")]
84-
p_info <- plyr::join(p_info, doms, by = "plot")
84+
p_info <- plyr::join(p_info, doms, by = "key")
8585
}
8686
# empty plot container that we'll fill up with new info
8787
p <- list(

tests/testthat/test-plotly-subplot.R

+14
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@ test_that("nrows argument works", {
2727
expect_true(doms$yaxis[1] >= doms$yaxis2[2])
2828
})
2929

30+
test_that("group + [x/y]axis works", {
31+
iris$id <- as.integer(iris$Species)
32+
p <- plot_ly(iris, x = Petal.Length, y = Petal.Width, group = Species,
33+
xaxis = paste0("x", id), mode = "markers")
34+
s <- expect_traces(subplot(p, margin = 0.05), 3, "group")
35+
doms <- lapply(s$layout, "[[", "domain")
36+
# make sure y domain is [0, 1] on every axis
37+
ydom <- doms[grepl("^y", names(doms))]
38+
expect_equal(sort(unique(unlist(ydom))), c(0, 1))
39+
xdom <- doms[grepl("^x", names(doms))]
40+
expect_true(all(1/3 > xdom[[1]] & xdom[[1]] >= 0))
41+
expect_true(all(2/3 > xdom[[2]] & xdom[[2]] > 1/3))
42+
expect_true(all(1 >= xdom[[3]] & xdom[[3]] > 2/3))
43+
})
3044

3145

3246

0 commit comments

Comments
 (0)