From feb7a58b7000a8bfbced6f52841e27c881645f06 Mon Sep 17 00:00:00 2001 From: cpsievert Date: Tue, 25 Aug 2015 10:26:57 -0500 Subject: [PATCH 1/2] key field tracks subplot counter, not plot; add a test for subplot with group/[x-y]axis specification --- R/subplots.R | 4 ++-- tests/testthat/test-plotly-subplot.R | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/R/subplots.R b/R/subplots.R index ab9bf2100f..b6ed8f51b9 100644 --- a/R/subplots.R +++ b/R/subplots.R @@ -79,9 +79,9 @@ subplot <- function(..., nrows = 1, which_layout = "merge", margin = 0.02) { # (I don't think it makes sense to support partial specification of domains) if (all(is.na(with(p_info, c(xstart, xend, ystart, yend))))) { doms <- get_domains(max(p_info$key), nrows, margin) - doms$plot <- as.character(seq_len(nrow(doms))) + doms$key <- as.character(seq_len(nrow(doms))) p_info <- p_info[!names(p_info) %in% c("xstart", "xend", "ystart", "yend")] - p_info <- plyr::join(p_info, doms, by = "plot") + p_info <- plyr::join(p_info, doms, by = "key") } # empty plot container that we'll fill up with new info p <- list( diff --git a/tests/testthat/test-plotly-subplot.R b/tests/testthat/test-plotly-subplot.R index 4f0a442fb9..170a3b7953 100644 --- a/tests/testthat/test-plotly-subplot.R +++ b/tests/testthat/test-plotly-subplot.R @@ -27,6 +27,20 @@ test_that("nrows argument works", { expect_true(doms$yaxis[1] >= doms$yaxis2[2]) }) +test_that("group + [x/y]axis works", { + iris$id <- as.integer(iris$Species) + p <- plot_ly(iris, x = Petal.Length, y = Petal.Width, group = Species, + xaxis = paste0("x", id), mode = "markers") + s <- expect_traces(subplot(p, margin = 0.05), 3, "group") + doms <- lapply(s$layout, "[[", "domain") + # make sure y domain is [0, 1] on every axis + ydom <- doms[grepl("^y", names(doms))] + expect_equal(sort(unique(unlist(ydom))), c(0, 1)) + xdom <- doms[grepl("^x", names(doms))] + expect_true(all(1/3 > xdom[[1]] & xdom[[1]] >= 0)) + expect_true(all(2/3 > xdom[[2]] & xdom[[2]] > 1/3)) + expect_true(all(1 >= xdom[[3]] & xdom[[3]] > 2/3)) +}) From 4bb006e70cf07b70e7f25e7ab209ce443c203ce9 Mon Sep 17 00:00:00 2001 From: cpsievert Date: Tue, 25 Aug 2015 10:41:48 -0500 Subject: [PATCH 2/2] Bump version; update NEWS --- DESCRIPTION | 2 +- NEWS | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index d7d098809e..3d4289ded3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: plotly Title: Create interactive web-based graphs via plotly's API -Version: 1.0.5 +Version: 1.0.6 Authors@R: c(person("Chris", "Parmer", role = c("aut", "cph"), email = "chris@plot.ly"), person("Scott", "Chamberlain", role = "aut", diff --git a/NEWS b/NEWS index 0158aede78..f0846302bb 100644 --- a/NEWS +++ b/NEWS @@ -1,3 +1,7 @@ +1.0.6 -- 25 Aug 2015 + +Fix a bug with subplot domain calculations (see https://github.com/ropensci/plotly/pull/274) + 1.0.5 -- 20 Aug 2015 Fix issue converting plotly offline markdown documents to HTML when using `markdown::markdownToHTML`