Legend order in scatter plot ignored when frame animation is used
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- R
- Star
- 2.7k
- Fork
- 641
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Mô tả
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.
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách chạy bản tái hiện R được cung cấp với tập dữ liệu gapminder và so sánh các biểu đồ có hoạt ảnh và không có hoạt ảnh. Theo dõi cách hoạt ảnh khung hình xử lý các mức của factor continent; công việc được hoàn thành khi biểu đồ phân tán có hoạt ảnh giữ nguyên thứ tự chú giải được xác định bởi dữ liệu mà không cần workaround traceorder.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- r
- Lĩnh vực
- data-visualization
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 30/100