Skip to content

Commit 061e43a

Browse files
committed
Merge pull request #508 from ropensci/fix/facetLabeller
Fix/facet labeller
2 parents ae20cba + c4a0a26 commit 061e43a

File tree

4 files changed

+34
-5
lines changed

4 files changed

+34
-5
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: plotly
22
Title: Create Interactive Web Graphics via 'plotly.js'
3-
Version: 3.4.2
3+
Version: 3.4.3
44
Authors@R: c(person("Carson", "Sievert", role = c("aut", "cre"),
55
email = "cpsievert1@gmail.com"),
66
person("Chris", "Parmer", role = c("aut", "cph"),

NEWS

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
1+
3.4.3 -- 14 Mar 2016
2+
3+
BUGFIX:
4+
5+
Custom facet labeller functions will now translate correctly. See #507.
6+
17
3.4.2 -- 14 Mar 2016
28

39
BUGFIX:
410

511
Automatic resizing will now occur only when layout.autosize is true (the default). See #403.
612

7-
813
3.4.1 -- 13 Mar 2016
914

1015
BUGFIX:

R/ggplotly.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,7 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A
303303
rep(panelMarginX, 2),
304304
rep(panelMarginY, 2)
305305
)
306+
306307
doms <- get_domains(nPanels, nRows, margins)
307308

308309
for (i in seq_len(nPanels)) {
@@ -428,12 +429,11 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A
428429
gglayout$shapes <- c(gglayout$shapes, border)
429430

430431
# facet strips -> plotly annotations
431-
# TODO: use p$facet$labeller for the actual strip text!
432432
if (!is_blank(theme[["strip.text.x"]]) &&
433433
(inherits(p$facet, "wrap") || inherits(p$facet, "grid") && lay$ROW == 1)) {
434434
vars <- ifelse(inherits(p$facet, "wrap"), "facets", "cols")
435435
txt <- paste(
436-
lay[, as.character(p$facet[[vars]])], collapse = ", "
436+
p$facet$labeller(lay[names(p$facet[[vars]])]), collapse = ", "
437437
)
438438
lab <- make_label(
439439
txt, x = mean(xdom), y = max(ydom),
@@ -447,7 +447,7 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A
447447
if (inherits(p$facet, "grid") && lay$COL == nCols && nRows > 1 &&
448448
!is_blank(theme[["strip.text.y"]])) {
449449
txt <- paste(
450-
lay[, as.character(p$facet$rows)], collapse = ", "
450+
p$facet$labeller(lay[names(p$facet$rows)]), collapse = ", "
451451
)
452452
lab <- make_label(
453453
txt, x = max(xdom), y = mean(ydom),

tests/testthat/test-ggplot-facets.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,27 @@ test_that("facet_wrap() doesn't create interior scales", {
9797
info <- save_outputs(g, "facet_wrap")
9898
expect_equal(unique(unlist(lapply(info$data, "[[", "yaxis"))), "y")
9999
})
100+
101+
102+
g <- ggplot(mtcars, aes(mpg, wt)) +
103+
geom_point() +
104+
facet_wrap( ~ am, labeller = label_both)
105+
106+
test_that("facet_wrap translates simple labeller function", {
107+
info <- save_outputs(g, "facet_wrap-labeller")
108+
txt <- sapply(info$layout$annotations, "[[", "text")
109+
expect_true(all(c("am: 0", "am: 1") %in% txt))
110+
})
111+
112+
g <- ggplot(mtcars, aes(mpg, wt)) +
113+
geom_point() +
114+
facet_grid(vs ~ am, labeller = label_both)
115+
116+
test_that("facet_grid translates simple labeller function", {
117+
info <- save_outputs(g, "facet_grid-labeller")
118+
txt <- sapply(info$layout$annotations, "[[", "text")
119+
expect_true(
120+
all(c("am: 0", "am: 1", "vs: 0", "vs: 1") %in% txt)
121+
)
122+
})
123+

0 commit comments

Comments
 (0)