@@ -459,27 +459,35 @@ gg2list <- function(p, width = NULL, height = NULL,
459
459
460
460
# panel -> plotly.js axis/anchor info
461
461
# (assume a grid layout by default)
462
- layout $ layout $ xaxis <- layout $ layout $ COL
463
- layout $ layout $ yaxis <- layout $ layout $ ROW
464
- layout $ layout $ xanchor <- nRows
465
- layout $ layout $ yanchor <- 1
462
+ layout $ layout <- dplyr :: mutate(layout $ layout ,
463
+ xaxis = COL ,
464
+ yaxis = ROW ,
465
+ xanchor = nRows ,
466
+ yanchor = 1L )
466
467
if (inherits(plot $ facet , " FacetWrap" )) {
467
- if (plot $ facet $ params $ free $ x ) {
468
- layout $ layout $ xaxis <- layout $ layout $ PANEL
469
- layout $ layout $ xanchor <- layout $ layout $ ROW
470
- }
471
- if (plot $ facet $ params $ free $ y ) {
472
- layout $ layout $ yaxis <- layout $ layout $ PANEL
473
- layout $ layout $ yanchor <- layout $ layout $ COL
474
- layout $ layout $ xanchor <- nPanels
475
- }
476
468
if (plot $ facet $ params $ free $ x && plot $ facet $ params $ free $ y ) {
477
- layout $ layout $ xaxis <- layout $ layout $ PANEL
478
- layout $ layout $ yaxis <- layout $ layout $ PANEL
479
- layout $ layout $ xanchor <- layout $ layout $ PANEL
480
- layout $ layout $ yanchor <- layout $ layout $ PANEL
469
+ layout $ layout <- dplyr :: mutate(layout $ layout ,
470
+ xaxis = PANEL ,
471
+ yaxis = PANEL ,
472
+ xanchor = PANEL ,
473
+ yanchor = PANEL )
474
+ } else if (plot $ facet $ params $ free $ x ) {
475
+ layout $ layout <- dplyr :: mutate(layout $ layout ,
476
+ xaxis = PANEL ,
477
+ xanchor = ROW )
478
+ } else if (plot $ facet $ params $ free $ y ) {
479
+ layout $ layout <- dplyr :: mutate(layout $ layout ,
480
+ yaxis = PANEL ,
481
+ yanchor = COL )
481
482
}
483
+ # anchor X axis to the lowest plot in its column
484
+ layout $ layout <- dplyr :: group_by(layout $ layout , xaxis ) %> %
485
+ dplyr :: mutate(xanchor = max(as.integer(yaxis ))) %> %
486
+ dplyr :: ungroup() %> %
487
+ dplyr :: mutate(xanchor = if (is.factor(yaxis )) levels(yaxis )[xanchor ] else xanchor )
482
488
}
489
+ layout $ layout <- as.data.frame(layout $ layout )
490
+
483
491
# format the axis/anchor to a format plotly.js respects
484
492
layout $ layout $ xaxis <- paste0(" xaxis" , sub(" ^1$" , " " , layout $ layout $ xaxis ))
485
493
layout $ layout $ yaxis <- paste0(" yaxis" , sub(" ^1$" , " " , layout $ layout $ yaxis ))
0 commit comments