@@ -38,18 +38,35 @@ ggplotly <- function(p = ggplot2::last_plot(), width = NULL, height = NULL,
38
38
# ' @export
39
39
ggplotly.ggmatrix <- function (p = ggplot2 :: last_plot(), width = NULL ,
40
40
height = NULL , tooltip = " all" , source = " A" , ... ) {
41
- plotList <- list ()
42
- for (i in seq_len(p $ nrow )) {
43
- for (j in seq_len(p $ ncol )) {
44
- plotList <- c(plotList , list (p [i , j ]))
41
+ subplotList <- list ()
42
+ for (i in seq_len(p $ ncol )) {
43
+ columnList <- list ()
44
+ for (j in seq_len(p $ nrow )) {
45
+ thisPlot <- p [j , i ]
46
+ if (i == 1 ) {
47
+ if (p $ showYAxisPlotLabels ) thisPlot <- thisPlot + ylab(p $ yAxisLabels [j ])
48
+ } else {
49
+ # y-axes are never drawn on the interior, and diagonal plots are densities,
50
+ # so it doesn't make sense to synch zoom actions on y
51
+ thisPlot <- thisPlot +
52
+ theme(
53
+ axis.ticks.y = element_blank(),
54
+ axis.text.y = element_blank()
55
+ )
56
+ }
57
+ columnList <- c(columnList , list (ggplotly(thisPlot , tooltip = tooltip )))
45
58
}
59
+ # conditioned on a column in a ggmatrix, the x-axis should be on the
60
+ # same scale.
61
+ s <- subplot(columnList , nrows = p $ nrow , margin = 0.01 , shareX = TRUE , titleY = TRUE )
62
+ # if (i == 3) browser()
63
+ subplotList <- c(subplotList , list (s ))
46
64
}
47
- # TODO:
48
- # (1) how to show x/y titles? Should these be arguments in subplot?
49
- # (2) it only makes since to share axes on the lower diagonal
50
- l <- get_plot(do.call(subplot , c(plotList , list (nrows = p $ nrow , ... ))))
51
- l $ layout $ title <- p $ title
52
- hash_plot(p $ data , l )
65
+ s <- subplot(subplotList , nrows = 1 )
66
+ if (nchar(p $ title ) > 0 ) {
67
+ s <- layout(s , title = p $ title )
68
+ }
69
+ layout(s , width = width , height = height )
53
70
}
54
71
55
72
# ' @export
@@ -673,8 +690,8 @@ gg2list <- function(p, width = NULL, height = NULL, tooltip = "all", source = "A
673
690
l <- list (data = setNames(traces , NULL ), layout = compact(gglayout ))
674
691
# ensure properties are boxed correctly
675
692
l <- add_boxed(rm_asis(l ))
676
- l $ width <- width
677
- l $ height <- height
693
+ l $ layout $ width <- width
694
+ l $ layout $ height <- height
678
695
l $ source <- source
679
696
structure(l , class = " plotly_built" )
680
697
}
0 commit comments