plotly / plotly/plotly.R

ggplotly dynamic ticks does not work with empty traces

Open
#1,713 0 comments 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

When using dynamicTicks for ggplotly in combination with dates, traces with empty data result in an error:

Error in as.POSIXct.default(x, origin = "1970-01-01", tz = scale$timezone) : 
  do not know how to convert 'x' to class "POSIXct"

This is because the invert_date function in gg2list() gets passed a NULL value (since no data exists for that specific layer).

p <- ggplot(mapping=aes(x=TIME, y=VAL)) +
  geom_point(data=data.frame(TIME=as.POSIXct(character()), VAL=numeric())) +
  geom_line(data=data.frame(TIME=c(Sys.time(), Sys.time()+lubridate::hours(2)), VAL=runif(2)))
plotly::ggplotly(p)
plotly::ggplotly(p, dynamicTicks=TRUE)

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 in gg2list(), focusing on the invert_date function mentioned in the report. Reproduce the supplied ggplotly example with an empty date trace and dynamicTicks=TRUE, then verify that the conversion no longer errors when a layer has no data.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.