Skip to content

Adding ggplotly() to the end of a pipe operation #1229

@ratnanil

Description

@ratnanil

I'm very used to the ggplot syntax and generate most plots with that library. Now and again, I'd like to turn my ggplot into a plotly plot. ggplotly ()works great for this.

data("diamonds")

library(ggplot2)
library(plotly)

data("cars")

p <- ggplot(diamonds,aes(carat,price)) +
  geom_point()

p %>%
  ggplotly()

It would be really elegant if one could add ggplotly() at the very end via piping. It nearly works, as shown in the code above. The following code however produces an error:

ggplot(diamonds,aes(carat,price)) +
  geom_point() %>%
  ggplotly()

#> Error in UseMethod("ggplotly", p) : 
#> no applicable method for 'ggplotly' applied to an object of class "c('LayerInstance', 'Layer', 'ggproto', 'gg')"

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