I know the function ggplotly() of the plotly package converts a ggplot2 object into a plotly one, but is there a function that does the reverse? Converts a plotly object to a ggplot2 one?
Boy do I have the solution for you!
We wrote a package to do this. It's called notly.
Notly R package
Installation:
# install.packages("devtools")
devtools::install_github("gdmcdonald/notly")
Example usage:
library(ggplot2)
library(plotly)
library(notly)
data(iris)
# Create a ggplot
ggplot_object <-
iris %>%
ggplot(aes(x = Sepal.Length,
y = Sepal.Width,
color = Species))+
geom_point()
# Create a plotly object - but with the ggplot hiding inside of it as well
notly_obj <-
ggplot_object %>%
ggplotly
notly_obj
# Extract the ggplot again
ggplot_obj_again <-
notly_obj %>%
notly
ggplot_obj_again
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With