plotly / plotly/plotly.R

Dynamic Axis Labels (Ticks) Misalignment with Data Points and Rangeslider

Đang mở
#2,426 2 bình luận 1 reaction 0 người được giao Xem trên GitHub

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ả

Description:

In my Plotly chart with a rangeslider, I'm facing a dilemma with axis labels (ticks). Without using tickvals, the chart incorrectly displays Sunday as the start of the week. When using tickvals to correct this, the axis labels don't dynamically adjust when zooming out, leading to overcrowding.

Expected Behavior:

  • The x-axis should consistently display Monday as the start of each week.
  • When zooming out, the axis should dynamically adjust to a coarser interval (e.g., every month, every quarter, or every year) to maintain readability.
  • The rangeslider should allow smooth navigation while preserving appropriate tick density at different zoom levels.

Actual Behavior:

  1. Without tickvals:
  • The chart incorrectly uses Sunday as the start of the week.

  • Zooming functions work as expected, with appropriate tick density at different zoom levels.

Image

  1. With tickvals:
  • The chart correctly displays Monday as the start of the week.

  • When zooming out, the axis doesn't adjust to a more appropriate interval, resulting in overcrowded and illegible labels.

Image

Reproducible Example:

library(shiny)
library(plotly)
library(lubridate)
library(dplyr)

# Example data
data <- data.frame(
  date = seq(as.Date("2024-01-01"), Sys.Date(), by = "day"),  
  value = runif(length(seq(as.Date("2024-01-01"), Sys.Date(), by = "day")), 10, 100)  
)

# Aggregate data by week
data_weekly <- data %>%
  mutate(week = floor_date(date, unit = "week", week_start = 1)) %>%
  group_by(week) %>% 
  summarise(value = sum(value)) 

# Create a plot with the week start as the x-axis
fig <- plot_ly(data = data_weekly,
               x = ~week,  
               y = ~value,  
               type = 'bar') %>%
  layout(xaxis = list(
    range = c(floor_date(max(data$date) - months(3) + days(4),
                         unit = "week", week_start = 1),  # Set the x-axis range starting 3 months before the latest date
              max(data$date + days(4))),  # Extend the range to the maximum date (with 4 extra days for buffer)
    tickvals = data_weekly$week  # Use the start of each week as the ticks on the x-axis
  )
  )


fig %>%
  config(displayModeBar = FALSE) %>%
  layout(xaxis = list(rangeslider = list(visible = TRUE)))  # Add a range slider for the x-axis

Additional Notes:

  • The issue arises from the need to use tickvals to enforce Monday as the week start, which then prevents Plotly's automatic tick adjustment.
  • An ideal solution would combine correct week start representation (Monday) with dynamic tick adjustment when zooming.

System info

R version: 4.3.3 (2024-02-29)
Plotly version: 4.10.4
Operating System: Linux 5.15.173.1-1.cm2

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu với ví dụ R có thể tái lập sử dụng plotly, lubridate, dplyr, tickvals và x-axis rangeslider. Điều tra cách các giá trị tick hàng tuần cố định tương tác với việc điều chỉnh tick do thao tác thu phóng; được xem là hoàn thành khi các nhãn hàng tuần dựa trên thứ Hai vẫn chính xác trong khi thao tác thu phóng thay đổi khoảng để tránh quá dày đặc.

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
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.