Skip to content

Commit 8d376d1

Browse files
authored
Merge pull request #1788 from trekonom/fix-axis-facets
Fix axis facets
2 parents c19594b + 642069d commit 8d376d1

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

Diff for: NEWS.md

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
## BUG FIXES
1212

13+
* `ggplotly()` now handles discrete axes of a `facet_wrap` and `facet_grid` correctly when there is only one category in panels > 1 (#1577 and #1720).
14+
1315
* `ggplotly()` now handles `element_blank()` and `factor()` labels in positional scales correctly (#1731 and #1772).
1416

1517
# 4.9.2.1

Diff for: R/utils.R

+1-1
Original file line numberDiff line numberDiff line change
@@ -521,7 +521,7 @@ verify_attr <- function(proposed, schema, layoutAttr = FALSE) {
521521

522522
# do the same for "sub-attributes"
523523
if (identical(role, "object") && is.recursive(proposed[[attr]])) {
524-
proposed[[attr]] <- verify_attr(proposed[[attr]], schema[[attr]], layoutAttr = layoutAttr)
524+
proposed[[attr]] <- verify_attr(proposed[[attr]], attrSchema, layoutAttr = layoutAttr)
525525
}
526526
}
527527

Diff for: tests/testthat/test-facet-axis.R

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
test_that("ggplotly does not break discrete x-axis with facet_yyyy in panels > 1 with only one category", {
2+
d <- data.frame(cat = c("A", "A", "A"), pan = paste("Panel", c(1, 2, 2)))
3+
gp <- ggplot(d, aes(cat)) +
4+
geom_bar() +
5+
facet_wrap(~pan)
6+
L <- plotly_build(ggplotly(gp))
7+
# tickvals, ticktext and categoryarray have class 'AsIs'
8+
lapply(L$x$layout[c("xaxis", "xaxis2")], function(axis) {
9+
expect_s3_class(axis$tickvals, "AsIs")
10+
expect_s3_class(axis$ticktext, "AsIs")
11+
expect_true(axis$ticktext == "A")
12+
expect_s3_class(axis$categoryarray, "AsIs")
13+
expect_true(axis$categoryarray == "A")
14+
})
15+
})

0 commit comments

Comments
 (0)