plotly / plotly/plotly.R

Bar plot shows too many ticks

Open
#2,421 1 comment 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

In plotly 4.10.4 a bar plot with only one date observation shows actually multiple ticks when the ticks' format is converted. Here a minimal reproducible example:

library(dplyr)
library(plotly)

df <- tibble(Time = "2025-01", Animal = "Monkey", value = 2)

df %>%
  plot_ly(x = ~Time, y= ~value, color = ~Animal) %>%
  layout(
    xaxis = list(
      type = "date",
      tickformat = "%b '%y"
    )
  )

Image

This is not the case though for a stacked bar plot:

df <- tibble(Time = c("2025-01", "2025-01"), Animal = c("Monkey", "Lion"), value = c(2, 3))

df %>%
  plot_ly(x = ~Time, y= ~value, color = ~Animal) %>%
  layout(
    barmode = "stacked",
    xaxis = list(
      type = "date",
      tickformat = "%b '%y"
    )
  )

Image

When looking at the dates without formatting one can see a few minimal shifts around the actual date:

df <- tibble(Time = "2025-01", Animal = "Monkey", value = 2)

df %>%
  plot_ly(x = ~Time, y= ~value, color = ~Animal) %>%
  layout(
    xaxis = list(
      type = "date"
    )
  )

Image

Is this already somewhere addressed?

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 single-observation R example with plot_ly() and the xaxis type and tickformat options, then compare it with the stacked-bar and unformatted examples. Trace how the date axis and tick formatting are handled; done means the single-date bar plot shows the expected tick without introducing extra formatted ticks, while the existing stacked behavior remains unchanged.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.