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?
1 Answer
Boy do I have the solution for you!
We wrote a package to do this. It's called notly.
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
1 Comment
carverd
I appreciate the work here but want to clarify. This package will allow you to go from ggplot -> plotly -> ggplot. It will not enable you to got from plotly -> ggplot
plotlyobject toggplot2. and I doubt it will ever be