Skip to content

Commit a60e1c9

Browse files
committed
Merge pull request #143 from ropensci/pedro-issuecomment-62256157
ggplot: legend: Improve title position
2 parents 4531e4f + 833d3a6 commit a60e1c9

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

R/ggplotly.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,9 @@ gg2list <- function(p){
495495
if (exists("increase_margin_r")) {
496496
layout$margin$r <- 60
497497
}
498-
layout$legend <- list(bordercolor="transparent", x=1, y=1/2)
498+
layout$legend <- list(bordercolor="transparent",
499+
x=1.05, y=1/2,
500+
xanchor="center", yanchor="top")
499501

500502
# Workaround for removing unnecessary legends.
501503
# [markUnique != "x"] is for boxplot's particular case.
@@ -520,11 +522,11 @@ gg2list <- function(p){
520522
nann <- 1
521523
}
522524
annotations[[nann]] <- list(text=legend.title,
523-
x=layout$legend$x * 1.013,
524-
y=layout$legend$y * (1 + (length(traces) * 0.04)) + 0.04,
525+
x=layout$legend$x,
526+
y=layout$legend$y * 1.04,
525527
showarrow=FALSE,
526528
xref="paper", yref="paper",
527-
xanchor="left", yanchor="top",
529+
xanchor="center",
528530
textangle=0)
529531
layout$annotations <- annotations
530532
}

0 commit comments

Comments
 (0)