@@ -277,6 +277,11 @@ gg2list <- function(p, width = NULL, height = NULL,
277277
278278 # Compute aesthetics to produce data with generalised variable names
279279 data <- by_layer(function (l , d ) l $ compute_aesthetics(d , plot ))
280+ if (exists(" setup_plot_labels" , envir = asNamespace(" ggplot2" ))) {
281+ # Mirror ggplot2/#5879
282+ plot $ labels <- ggfun(" setup_plot_labels" )(plot , layers , data )
283+ }
284+
280285
281286 # add frame to group if it exists
282287 data <- lapply(data , function (d ) {
@@ -463,12 +468,8 @@ gg2list <- function(p, width = NULL, height = NULL,
463468 assign(var , built_env [[var ]], envir = envir )
464469 }
465470
466- # initiate plotly.js layout with some plot-wide theming stuff
467- theme <- ggfun(" plot_theme" )(plot )
468- elements <- names(which(sapply(theme , inherits , " element" )))
469- for (i in elements ) {
470- theme [[i ]] <- ggplot2 :: calc_element(i , theme )
471- }
471+ theme <- calculated_theme_elements(plot )
472+
472473 # Translate plot wide theme elements to plotly.js layout
473474 pm <- unitConvert(theme $ plot.margin , " pixels" )
474475 gglayout <- list (
@@ -1154,6 +1155,23 @@ gg2list <- function(p, width = NULL, height = NULL,
11541155# Due to the non-standard use of assign() in g2list() (above)
11551156utils :: globalVariables(c(" groupDomains" , " layers" , " prestats_data" , " scales" , " sets" ))
11561157
1158+ # Get the "complete" set of theme elements and their calculated values
1159+ calculated_theme_elements <- function (plot ) {
1160+ if (is.function(asNamespace(" ggplot2" )$ complete_theme )) {
1161+ theme <- ggplot2 :: complete_theme(plot $ theme )
1162+ elements <- names(theme )
1163+ } else {
1164+ theme <- ggfun(" plot_theme" )(plot )
1165+ elements <- names(which(sapply(theme , inherits , " element" )))
1166+ }
1167+
1168+ for (i in elements ) {
1169+ theme [[i ]] <- ggplot2 :: calc_element(i , theme )
1170+ }
1171+
1172+ theme
1173+ }
1174+
11571175
11581176# -----------------------------------------------------------------------------
11591177# ggplotly 'utility' functions
@@ -1384,7 +1402,8 @@ rect2shape <- function(rekt = ggplot2::element_rect()) {
13841402 linetype = lty2dash(rekt $ linetype )
13851403 ),
13861404 yref = " paper" ,
1387- xref = " paper"
1405+ xref = " paper" ,
1406+ layer = " below"
13881407 )
13891408}
13901409
@@ -1408,6 +1427,7 @@ gdef2trace <- function(gdef, theme, gglayout) {
14081427 # N.B. ggplot2 >v3.4.2 (specifically #4879) renamed bar to decor and also
14091428 # started returning normalized values for the key field
14101429 decor <- gdef $ decor %|| % gdef $ bar
1430+ decor $ value <- decor $ value %|| % decor $ max
14111431 rng <- range(decor $ value )
14121432 decor $ value <- scales :: rescale(decor $ value , from = rng )
14131433 if (! " decor" %in% names(gdef )) {
0 commit comments