Skip to content

subplot() bugfix #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 25, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
4 changes: 4 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -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`
4 changes: 2 additions & 2 deletions R/subplots.R
Original file line number Diff line number Diff line change
@@ -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(
14 changes: 14 additions & 0 deletions tests/testthat/test-plotly-subplot.R
Original file line number Diff line number Diff line change
@@ -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))
})