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')"
I'm very used to the
ggplotsyntax and generate most plots with that library. Now and again, I'd like to turn myggplotinto aplotlyplot.ggplotly ()works great for this.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: