Legend order in scatter plot ignored when frame animation is used
Ninguém assumiu esta issue ainda.
- Linguagem predominante
- R
- Estrelas
- 2.7k
- Forks
- 641
- Métricas de merge de PRs
- Nenhum PR com merge em 30d
Descrição
Hello everyone!
I'm currently working on a dashboard for monitoring in R and would like use Plotly's animated scatter plot, which works like a charm except for the legend order. Indepentent from how I define the order within the code, the order defaults to alphabetical.
Here's a code to reproduce the issue based on the gapminder dataset. To demonstrate the issue, I've reordered the continent factor variable by reversing the levels and it still shows in alphabetical order. The same happens, when I hardcode the order into the levels parameter.
library(tidyverse)
library(plotly)
library(gapminder)
gapdf <- gapminder
fig <- gapdf %>%
mutate(
continent = factor(continent, levels = rev(levels(continent)))
) %>%
plot_ly(
x = ~gdpPercap,
y = ~lifeExp,
size = ~pop,
color = ~continent,
frame = ~year,
text = ~country,
hoverinfo = "text",
type = 'scatter',
fill = ~'',
mode = 'markers'
)
fig <- fig %>% layout(
xaxis = list(
type = "log"
)
)
fig <- fig %>% animation_opts(
1000, easing = "elastic", redraw = FALSE
)
fig <- fig %>% animation_button(
x = 1, xanchor = "right", y = 0, yanchor = "bottom"
)
fig <- fig %>% animation_slider(
currentvalue = list(prefix = "YEAR ", font = list(color="#CC0033"))
)
fig

When "frame" and its corresponding animation commands are excluded, the legend order works as intended:
library(tidyverse)
library(plotly)
library(gapminder)
gapdf <- gapminder
fig <- gapdf %>%
mutate(
continent = factor(continent, levels = rev(levels(continent)))
) %>%
plot_ly(
x = ~gdpPercap,
y = ~lifeExp,
size = ~pop,
color = ~continent,
text = ~country,
hoverinfo = "text",
type = 'scatter',
fill = ~'',
mode = 'markers'
)
fig

Reversing the order is only possible through adjusting the traceorder of the legend, but I would like to use the order of the levels as provided by the data, which is not alphabetical or reversed alphabetical in 99,9% of my cases, so this workaround won't help.
If anyone knows a proper workaround, I would highly appreciate it!
Kind regards and have a nice day everyone.
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Direção de pesquisa
Comece executando a reprodução fornecida em R com o conjunto de dados gapminder e compare os gráficos animado e não animado. Rastreie como a animação de frames trata os níveis do fator continent; o trabalho estará concluído quando o gráfico de dispersão animado preservar a ordem da legenda definida pelos dados sem exigir um workaround de traceorder.
Escrita pelo modelo de indexação a partir do texto da issue.
Avaliação
- Stack de tecnologia
- r
- Domínio
- data-visualization
- Tipo de issue
- Bug
- Dificuldade
- 4/5
- Tempo estimado
- 3-5 dias
- Status de atividade
- Estagnada
- Clareza
- Razoavelmente clara
- Facilidade para iniciantes
- 30/100