plotly / plotly/plotly.R

ggplotly barcharts with Dates and dynamicTicks=T

Open
#1,364 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

I experience a weird behaviour when using barcharts with Dates on the x-Axis and dynamicTicks=T.

1 bar of the example (4th July) is in a different color, it doesnt show up and the highlight function also doesnt color the clicked bar, although the legend suggests otherwise.

When converting the Dates to character, everything shows up correctly and also the highlight function shows up, but the labels look horrible.


Plot with Dates

library(ggplot2)
library(plotly)

dfN <- data.frame(
  time_stamp = seq.Date(as.Date("2018-04-01"), as.Date("2018-07-30"), 1),
  val = runif(121, 100,1000),
  col = "green", stringsAsFactors = F
)

dfN[95,]$col = "orange"

maxY = max(dfN$val)
key <- highlight_key(dfN)

p <- ggplot() +
  geom_col(data = key, aes(x = (time_stamp), y = val, fill=I(col)), width = 1)

## 4 of July doesnt show at all (should show an orange bar)
ggplotly(p, source = "Src", dynamicTicks = T, originalData = T) %>%
  highlight(selectize=F, on="plotly_click", off = "plotly_doubleclick", color = "blue")

rplot


Plot with Characters

p <- ggplot() +
  geom_col(data = key, aes(x = as.character(time_stamp), y = val, fill=I(col)), width = 1) +
  ggtitle("Characters on x-Axis")

ggplotly(p, source = "Src", dynamicTicks = T, originalData = T) %>%
  highlight(selectize=F, on="plotly_click", off = "plotly_doubleclick", color = "blue")

rplot02

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 issue's reproducible R example in plotly.R and compare the Date and character x-axis cases with dynamicTicks and highlight enabled. Done means the July 4 bar is rendered with the expected color and clicking it applies the highlight correctly while retaining usable date labels.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.