From 5dd5ab236c1a35ee17a79f02a292c7e3b1253a7c Mon Sep 17 00:00:00 2001 From: Alexey Stukalov Date: Fri, 3 Jun 2016 11:39:27 +0200 Subject: [PATCH 1/2] fix the axes layout for facet_wrap() --- R/ggplotly.R | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/R/ggplotly.R b/R/ggplotly.R index a1ab6b6522..96c5feaca6 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -212,10 +212,11 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A } } # format the axis/anchor to a format plotly.js respects - panel$layout$xaxis <- paste0("xaxis", sub("1", "", panel$layout$xaxis)) - panel$layout$yaxis <- paste0("yaxis", sub("1", "", panel$layout$yaxis)) - panel$layout$xanchor <- paste0("y", sub("1", "", panel$layout$xanchor)) - panel$layout$yanchor <- paste0("x", sub("1", "", panel$layout$yanchor)) + plotlyjs_axis_label <- function(prefix, ixs) paste0(prefix, ifelse(as.integer(ixs) > 1, ixs, "")) + panel$layout$xaxis <- plotlyjs_axis_label("xaxis", panel$layout$xaxis) + panel$layout$yaxis <- plotlyjs_axis_label("yaxis", panel$layout$yaxis) + panel$layout$xanchor <- plotlyjs_axis_label("y", panel$layout$xanchor) + panel$layout$yanchor <- plotlyjs_axis_label("x", panel$layout$yanchor) # for some layers2traces computations, we need the range of each panel panel$layout$x_min <- sapply(panel$ranges, function(z) min(z$x.range)) panel$layout$x_max <- sapply(panel$ranges, function(z) max(z$x.range)) From d9611aeb90e2d9f5eceafded02d971c1d9e8c6e3 Mon Sep 17 00:00:00 2001 From: Alexey Stukalov Date: Sun, 5 Jun 2016 21:42:49 +0200 Subject: [PATCH 2/2] ggplotly: fix Xaxis anchor if the last row incomplete attach X axis to the last non-empty row in a column --- R/ggplotly.R | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/R/ggplotly.R b/R/ggplotly.R index 96c5feaca6..7615e8f95e 100644 --- a/R/ggplotly.R +++ b/R/ggplotly.R @@ -191,10 +191,12 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A # panel -> plotly.js axis/anchor info # (assume a grid layout by default) - panel$layout$xaxis <- panel$layout$COL - panel$layout$yaxis <- panel$layout$ROW - panel$layout$xanchor <- nRows - panel$layout$yanchor <- 1 + panel$layout <- dplyr::mutate( panel$layout, + xaxis = COL, yaxis = ROW, + yanchor = 1L ) %>% + dplyr::group_by( xaxis ) %>% + dplyr::mutate( xanchor = max(ROW) ) %>% # anchor X axis to the lowest plot in the column + dplyr::ungroup() %>% as.data.frame() if (inherits(p$facet, "wrap")) { if (p$facet$free$x) { panel$layout$xaxis <- panel$layout$PANEL