@@ -223,6 +223,9 @@ subplot <- function(..., nrows = 1, widths = NULL, heights = NULL, margin = 0.02
223
223
data = Reduce(c , traces ),
224
224
layout = Reduce(modify_list , c(xAxes , rev(yAxes )))
225
225
)
226
+ # retrain default coloring
227
+ p $ data <- retrain_color_defaults(p $ data )
228
+
226
229
# reposition shapes and annotations
227
230
annotations <- Map(reposition , annotations , split(domainInfo , seq_along(plots )))
228
231
shapes <- Map(reposition , shapes , split(domainInfo , seq_along(plots )))
@@ -333,3 +336,19 @@ reposition <- function(obj, domains) {
333
336
}
334
337
obj
335
338
}
339
+
340
+
341
+ retrain_color_defaults <- function (traces ) {
342
+ colorDefaults <- traceColorDefaults()
343
+ for (i in seq_along(traces )) {
344
+ # https://github.com/plotly/plotly.js/blob/c83735/src/plots/plots.js#L58
345
+ idx <- i %% length(colorDefaults ) + i %/% length(colorDefaults )
346
+ newDefault <- colorDefaults [[idx ]]
347
+ for (j in c(" marker" , " line" , " text" )) {
348
+ alpha <- attr(traces [[i ]][[j ]][[" color" ]], " defaultAlpha" )
349
+ if (is.null(alpha )) next
350
+ traces [[i ]][[j ]][[" color" ]] <- toRGB(colorDefaults [[idx ]], alpha )
351
+ }
352
+ }
353
+ traces
354
+ }
0 commit comments