Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: convert ggplot to plotly by adding a layer #1599

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

atusy
Copy link

@atusy atusy commented Aug 15, 2019

By this PR, we can convert ggplot to plotly by implementing gginteractive().
In addition, gginteractive has the interactive argument to control the conversion.

ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  gginteractive()
  # gginteractive(FALSE) # can suppress conversion

This is a sort of syntax sugar for ggplotly(), which has to wrap whole ggplot:

ggplotly(
  ggplot(mtcars, aes(wt, mpg)) +
  geom_point()
)

@cpsievert
Copy link
Collaborator

Interesting, thanks! Is there a way we could do this without introducing a new function? That is, could something like this work?

ggplot(mtcars, aes(wt, mpg)) +
  geom_point() +
  ggplotly()

@atusy
Copy link
Author

atusy commented Sep 4, 2019

Well, I wanted to do so.
I did not do it because the first argument of ggplotly is last_plot().
If it is missing or NULL, we can do what we want by

if (missing(p)) return(ggintearactive())
# or
if (is.nuill(p)) return(gginteractive())

The only way is to add a new argument like

ggplotly <- function(..., layer = FALSE) {
  if (layer) return(gginteractive())
  ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants