Skip to content

NA in dataset leads to truncated line #716

@jrowen

Description

@jrowen

I'm running into an issue plotting a line chart for multiple series when one of the underlying data series includes NA. The code below generates a chart with the complete series being truncated to match the incomplete series. Although you can't see it from the picture, moving the mouse along the front part of the chart shows values, almost as if the line is there but the color is translucent.

dts = seq(from = as.Date("2016-01-01"), to = Sys.Date(), by = "day")
DT = rbind(data.table(Date = dts, Group = "A", Value = rnorm(length(dts))),
           data.table(Date = dts, Group = "B", 
                      Value = c(rep(NA, length(dts) / 2), rnorm(length(dts) / 2))))
plot_ly(DT[order(Date, Group)]) %>%
  add_lines(x = ~Date, y = ~Value, color = ~Group)

newplot

I think the problem has to do with the data order, as the update below results in the expected output.

plot_ly(DT) %>%
  add_lines(x = ~Date, y = ~Value, color = ~Group)

newplot 1

In my case, it appears I can get around this issue by sorting my dataset before plotting (stack the series instead of co-mingle the data).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions