Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3f3d875

Browse filesBrowse files
authored
Merge pull request #1501 from alyst/fix_wrap_axes
ggplotly(): fix Xaxis anchor if the last row incomplete
2 parents 3bdb921 + ddb8b30 commit 3f3d875
Copy full SHA for 3f3d875

File tree

6 files changed

+36
-21
lines changed
Filter options

6 files changed

+36
-21
lines changed

‎R/ggplotly.R

Copy file name to clipboardExpand all lines: R/ggplotly.R
+31-17Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -465,27 +465,41 @@ gg2list <- function(p, width = NULL, height = NULL,
465465

466466
# panel -> plotly.js axis/anchor info
467467
# (assume a grid layout by default)
468-
layout$layout$xaxis <- layout$layout$COL
469-
layout$layout$yaxis <- layout$layout$ROW
470-
layout$layout$xanchor <- nRows
471-
layout$layout$yanchor <- 1
468+
layout$layout <- dplyr::mutate(
469+
layout$layout,
470+
xaxis = COL,
471+
yaxis = ROW,
472+
xanchor = nRows,
473+
yanchor = 1L
474+
)
472475
if (inherits(plot$facet, "FacetWrap")) {
473-
if (plot$facet$params$free$x) {
474-
layout$layout$xaxis <- layout$layout$PANEL
475-
layout$layout$xanchor <- layout$layout$ROW
476-
}
477-
if (plot$facet$params$free$y) {
478-
layout$layout$yaxis <- layout$layout$PANEL
479-
layout$layout$yanchor <- layout$layout$COL
480-
layout$layout$xanchor <- nPanels
481-
}
482476
if (plot$facet$params$free$x && plot$facet$params$free$y) {
483-
layout$layout$xaxis <- layout$layout$PANEL
484-
layout$layout$yaxis <- layout$layout$PANEL
485-
layout$layout$xanchor <- layout$layout$PANEL
486-
layout$layout$yanchor <- layout$layout$PANEL
477+
layout$layout <- dplyr::mutate(
478+
layout$layout,
479+
xaxis = PANEL,
480+
yaxis = PANEL,
481+
xanchor = PANEL,
482+
yanchor = PANEL
483+
)
484+
} else if (plot$facet$params$free$x) {
485+
layout$layout <- dplyr::mutate(
486+
layout$layout,
487+
xaxis = PANEL,
488+
xanchor = ROW
489+
)
490+
} else if (plot$facet$params$free$y) {
491+
layout$layout <- dplyr::mutate(
492+
layout$layout,
493+
yaxis = PANEL,
494+
yanchor = COL
495+
)
487496
}
497+
# anchor X axis to the lowest plot in its column
498+
layout$layout <- dplyr::group_by_(layout$layout, "xaxis")
499+
layout$layout <- dplyr::mutate(layout$layout, xanchor = max(as.integer(yaxis)))
488500
}
501+
layout$layout <- as.data.frame(layout$layout)
502+
489503
# format the axis/anchor to a format plotly.js respects
490504
layout$layout$xaxis <- paste0("xaxis", sub("^1$", "", layout$layout$xaxis))
491505
layout$layout$yaxis <- paste0("yaxis", sub("^1$", "", layout$layout$yaxis))

‎inst/docker/Dockerfile.vtest

Copy file name to clipboardExpand all lines: inst/docker/Dockerfile.vtest
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ EXPOSE 3838
9292

9393
RUN R -e "install.packages('assertthat')"
9494
RUN R -e "install.packages('testthat')"
95+
ARG CRANCACHE=1
9596
RUN R -e "update.packages(ask=FALSE)"
9697

9798
# install any new dependencies, then either manage cases (the default) or run tests

‎tests/figs/facets/facet-wrap-free-y-2.svg

Copy file name to clipboardExpand all lines: tests/figs/facets/facet-wrap-free-y-2.svg
+1-1Lines changed: 1 addition & 1 deletion
Loading

‎tests/figs/facets/facet-wrap-free-y.svg

Copy file name to clipboardExpand all lines: tests/figs/facets/facet-wrap-free-y.svg
+1-1Lines changed: 1 addition & 1 deletion
Loading

‎tests/figs/smooth/smooth-facet.svg

Copy file name to clipboardExpand all lines: tests/figs/smooth/smooth-facet.svg
+1-1Lines changed: 1 addition & 1 deletion
Loading

‎tests/testthat/test-ggplot-facets.R

Copy file name to clipboardExpand all lines: tests/testthat/test-ggplot-facets.R
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,5 +140,5 @@ test_that("when y scales are free, x-axes are still anchored on exterior", {
140140
info <- expect_doppelganger_built(p, "facet_wrap-free_y-2")
141141
xaxes <- info$layout[grep("^xaxis", names(info$layout))]
142142
yaxes <- info$layout[grep("^yaxis", names(info$layout))]
143-
expect_equivalent(unique(sapply(xaxes, "[[", "anchor")), "y5")
143+
expect_equivalent(unique(sapply(xaxes, "[[", "anchor")), c("y5", "y4"))
144144
})

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.