Skip to content

ggplotly fails with an empty layer of geom_vline #1947

@jarauh

Description

@jarauh

ggplotly fails when there is a geom_vline-layer that does not contain any lines. For me, this happens in a setting where I have a function that computes a set of x-values at which I want to have vertical lines. Sometimes it happens that no vertical line is needed, and then ggplotly fails with the following error message:

Fehler in fix.by(by.y, y) : 'by' must specify a uniquely valid column

Minimal example:

do_plot <- function(xintercepts) {
  ggplot(mtcars, aes(mpg, carb)) + geom_point() +
    geom_vline(xintercept = xintercepts)
}
plotly::ggplotly(do_plot(23))        # works fine
plotly::ggplotly(do_plot(c(15, 25))) # works fine
plotly::ggplotly(do_plot(numeric())) # produces error (but works without call to ggplotly)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions