21

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?

2
  • 7
    No there is not. It's not possible to cast a plotly object to ggplot2. and I doubt it will ever be Commented Jul 25, 2017 at 14:45
  • That's unfortunate...thank you though! Commented Jul 25, 2017 at 15:15

1 Answer 1

2

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
Sign up to request clarification or add additional context in comments.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.