@@ -24,8 +24,11 @@ subplot <- function(..., nrows = 1, which_layout = "merge", margin = 0.02) {
24
24
# build each plot
25
25
plots <- lapply(list (... ), plotly_build )
26
26
# rename axes, respecting the fact that each plot could be a subplot itself
27
- layouts <- lapply(plots , " [[" , " layout" )
28
27
traces <- lapply(plots , " [[" , " data" )
28
+ layouts <- lapply(plots , " [[" , " layout" )
29
+
30
+ annotations <- compact(lapply(layouts , " [[" , " annotations" ))
31
+ shapes <- compact(lapply(layouts , " [[" , " shapes" ))
29
32
xAxes <- lapply(layouts , function (x ) {
30
33
x [grepl(" ^xaxis" , names(x ))] %|| %
31
34
list (xaxis = list (domain = c(0 , 1 ), anchor = " y" ))
@@ -55,6 +58,8 @@ subplot <- function(..., nrows = 1, which_layout = "merge", margin = 0.02) {
55
58
for (i in seq_along(plots )) {
56
59
xMap <- xAxisMap [[i ]]
57
60
yMap <- yAxisMap [[i ]]
61
+ xDom <- as.numeric(domainInfo [i , c(" xstart" , " xend" )])
62
+ yDom <- as.numeric(domainInfo [i , c(" yend" , " ystart" )])
58
63
for (j in seq_along(xAxes [[i ]])) {
59
64
# before bumping axis anchor, bump trace info, where appropriate
60
65
traces [[i ]] <- lapply(traces [[i ]], function (tr ) {
@@ -64,10 +69,9 @@ subplot <- function(..., nrows = 1, which_layout = "merge", margin = 0.02) {
64
69
# bump anchors
65
70
map <- yMap [yMap %in% sub(" y" , " yaxis" , xAxes [[i ]][[j ]]$ anchor )]
66
71
xAxes [[i ]][[j ]]$ anchor <- sub(" axis" , " " , names(map ))
72
+ browser()
67
73
xAxes [[i ]][[j ]]$ domain <- sort(scales :: rescale(
68
- xAxes [[i ]][[j ]]$ domain ,
69
- as.numeric(domainInfo [i , c(" xstart" , " xend" )]),
70
- from = c(0 , 1 )
74
+ xAxes [[i ]][[j ]]$ domain , xDom , from = c(0 , 1 )
71
75
))
72
76
}
73
77
for (j in seq_along(yAxes [[i ]])) {
@@ -78,9 +82,7 @@ subplot <- function(..., nrows = 1, which_layout = "merge", margin = 0.02) {
78
82
map <- xMap [xMap %in% sub(" x" , " xaxis" , yAxes [[i ]][[j ]]$ anchor )]
79
83
yAxes [[i ]][[j ]]$ anchor <- sub(" axis" , " " , names(map ))
80
84
yAxes [[i ]][[j ]]$ domain <- sort(scales :: rescale(
81
- yAxes [[i ]][[j ]]$ domain ,
82
- as.numeric(domainInfo [i , c(" yend" , " ystart" )]),
83
- from = c(0 , 1 )
85
+ yAxes [[i ]][[j ]]$ domain , yDom , from = c(0 , 1 )
84
86
))
85
87
}
86
88
xAxes [[i ]] <- setNames(xAxes [[i ]], names(xMap ))
0 commit comments