plotly / plotly/plotly.R

Cannot change colour legend position for continuous variable

Open
#2,048 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
R
Stars
2.7k
Forks
641
PR merge metrics
No merged PRs in 30d

Description

Locked question #1049 relates to the same issue, which still persists. Changing legend position is fiddly but works ok for factor variable:

require(ggplot2)
require(ggmap)
require(plotly)

m = c(left=60.5, bottom =29.3, right = 75.2, top = 38.5) |> 
  ggmap::get_stamenmap(maptype = 'toner', zoom = 6)

d = data.frame(x = rnorm(mean = 65, sd = 3, 50), 
               y = rnorm(mean = 34, sd = 2, 50))

p1 = ggmap(m) + 
  geom_point(data=d, aes(x, y, col = factor(round(x))), size=3) +
  labs(col = 'Eastness', x = NULL, y = NULL) +
  theme_void()

ggplotly(p1) |> layout(legend = list(xanchor  = "left", x = 0, yanchor = "bottom", y = 0.2))
image

But for a continuous variable this fails:

p2 = ggmap(m) + 
  geom_point(data=d, aes(x, y, col = x), size=3) +
  labs(col = 'Eastness', x = NULL, y = NULL) +
  theme_void()

ggplotly(p2) |> layout(legend = list(xanchor  = "left", x = 0, yanchor = "bottom", y = 0.2))
image

This seems to me this is a pretty basic and important thing to get right. I wonder if there's any chance to fix?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by running the reproducible R examples for p1 and p2 in the issue, comparing factor and continuous colour legends after the layout call. Trace how ggplotly converts each legend and how layout positioning is applied. Done means the continuous colour legend moves to the requested position without breaking the factor case.

Written by the indexing model from the issue text.

Assessment

Tech stack
r
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.