@@ -411,7 +411,6 @@ gg2list <- function(p, width = NULL, height = NULL,
411411 # of each non-positional scale for display in tooltips
412412 for (sc in npscales $ scales ) {
413413 data <- lapply(data , function (d ) {
414- # Only process aesthetics that actually exist in this layer's data
415414 present_aes <- intersect(sc $ aesthetics , names(d ))
416415 if (length(present_aes ) > 0 ) {
417416 d [paste0(present_aes , " _plotlyDomain" )] <- d [present_aes ]
@@ -573,12 +572,9 @@ gg2list <- function(p, width = NULL, height = NULL,
573572 tr $ hoverinfo <- tr $ hoverinfo %|| %" text"
574573 tr
575574 })
576- # show only one legend entry per legendgroup
577- # For deduplication, skip invisible traces (like GeomBlank) so they don't
578- # "claim" the legendgroup and prevent visible traces from showing in legend
575+ # show only one legend entry per legendgroup (skip invisible traces for dedup)
579576 grps <- sapply(traces , " [[" , " legendgroup" )
580577 is_visible <- sapply(traces , function (tr ) ! isFALSE(tr $ visible ))
581- # Only consider visible traces for deduplication - invisible traces shouldn't claim legendgroup
582578 grps_for_dedup <- ifelse(is_visible , grps , paste0(grps , " _invisible_" , seq_along(grps )))
583579 traces <- Map(function (x , y ) {
584580 if (! is.null(x [[" frame" ]])) return (x )
@@ -990,7 +986,7 @@ gg2list <- function(p, width = NULL, height = NULL,
990986 font = text2font(theme $ legend.text )
991987 )
992988
993- # Translate legend.position from ggplot2 theme to plotly layout (fixes #2407, #2187)
989+ # Translate legend.position to plotly layout
994990 legend_pos <- theme $ legend.position %|| % theme [[" legend.position" ]]
995991 if (! is.null(legend_pos ) && ! identical(legend_pos , " none" )) {
996992 if (is.character(legend_pos )) {
@@ -1005,7 +1001,6 @@ gg2list <- function(p, width = NULL, height = NULL,
10051001 x = - 0.15 , y = 0.5 , xanchor = " right" , yanchor = " middle"
10061002 )),
10071003 " inside" = {
1008- # In ggplot2 >= 3.5.0, numeric position is stored in legend.position.inside
10091004 inside_pos <- theme $ legend.position.inside %|| % theme [[" legend.position.inside" ]]
10101005 if (is.numeric(inside_pos ) && length(inside_pos ) == 2 ) {
10111006 modifyList(gglayout $ legend , list (
@@ -1015,10 +1010,9 @@ gg2list <- function(p, width = NULL, height = NULL,
10151010 gglayout $ legend
10161011 }
10171012 },
1018- gglayout $ legend # "right" is default, no change needed
1013+ gglayout $ legend
10191014 )
10201015 } else if (is.numeric(legend_pos ) && length(legend_pos ) == 2 ) {
1021- # Handle numeric position like c(0.8, 0.2) for older ggplot2 versions
10221016 gglayout $ legend <- modifyList(gglayout $ legend , list (
10231017 x = legend_pos [1 ], y = legend_pos [2 ], xanchor = " left" , yanchor = " bottom"
10241018 ))
@@ -1431,7 +1425,6 @@ make_strip_rect <- function(xdom, ydom, theme, side = "top") {
14311425# theme(panel.border) -> plotly.js rect shape
14321426make_panel_border <- function (xdom , ydom , theme ) {
14331427 border <- theme [[" panel.border" ]]
1434- # Don't draw anything if panel.border is blank or NULL
14351428 if (is.null(border ) || is_blank(border )) {
14361429 return (list ())
14371430 }
0 commit comments