Skip to content

Commit c465722

Browse files
committed
fix legend position
1 parent 20b7ad7 commit c465722

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

R/ggplotly.R

+7-6
Original file line numberDiff line numberDiff line change
@@ -628,9 +628,9 @@ gg2list <- function(p) {
628628
if (exists("increase_margin_r", where = as.environment("package:plotly"))) {
629629
layout$margin$r <- 60
630630
}
631-
layout$legend <- list(bordercolor="transparent",
632-
x=1.05, y=1/2,
633-
xanchor="center", yanchor="top")
631+
layout$legend <- list(bordercolor = "transparent",
632+
x = 1.01, y = 0.5,
633+
xanchor = "left", yanchor = "center")
634634

635635
## Legend hiding when guides(fill="none").
636636
legends.present <- unique(unlist(layer.legends))
@@ -674,11 +674,12 @@ gg2list <- function(p) {
674674
nann <- 1
675675
}
676676
annotations[[nann]] <- list(text=legend.title,
677-
x=layout$legend$x,
678-
y=layout$legend$y * 1.04,
677+
x= layout$legend$x * 1.0154,
678+
y= layout$legend$y +
679+
0.5 * length(trace.list) * 0.10,
679680
showarrow=FALSE,
680681
xref="paper", yref="paper",
681-
xanchor="center",
682+
xanchor="left", yanchor = "center",
682683
textangle=0)
683684
layout$annotations <- annotations
684685
}

0 commit comments

Comments
 (0)