@@ -223,6 +223,9 @@ subplot <- function(..., nrows = 1, widths = NULL, heights = NULL, margin = 0.02
223223 data = Reduce(c , traces ),
224224 layout = Reduce(modify_list , c(xAxes , rev(yAxes )))
225225 )
226+ # retrain default coloring
227+ p $ data <- retrain_color_defaults(p $ data )
228+
226229 # reposition shapes and annotations
227230 annotations <- Map(reposition , annotations , split(domainInfo , seq_along(plots )))
228231 shapes <- Map(reposition , shapes , split(domainInfo , seq_along(plots )))
@@ -333,3 +336,19 @@ reposition <- function(obj, domains) {
333336 }
334337 obj
335338}
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