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

geom_xspline not implemented in plotly - getting error message when using ggplotly() function #2405

Open
marinecdf opened this issue Dec 5, 2024 · 0 comments

Comments

@marinecdf
Copy link

I get an error message when trying to implement geom_xspline with
plotly.

I get the desired graph in ggplot2 but the plot cannot be converted to a
plotly object when using the ggplotly function.
You can find the code showcasing this below.

library(pacman)
pacman::p_load(tidyverse, datasets, plotly, ggplotly, ggalt)
# airmiles built-in dataset: 
airmiles <- datasets::airmiles
year <- 1937:1960
airmiles <- data.frame(year = year, airmiles = airmiles)


# "line" plot using geom_xspline from ggalt package: 
plot_airmiles <- ggplot(data = airmiles, 
              aes(x = year, y = airmiles)) + 
  geom_point(alpha = 0.75) + 
  geom_xspline(spline_shape = -0.7) +
  scale_y_continuous(n.breaks = 10) 

plot_airmiles

Image

# interactive plot: using ggplotly doesn't work
ggplotly(plot_airmiles)

Image

Could this be implemented in plotly? Is there any way I can still
produce the interactive graph in plotly without waiting for this to be
implemented?

The plotly documentation (https://linking.plotly-r.com/custom-geoms)
mentions the possibility of creating custom geoms and using the
to_basic() function from the plotly package to “convert” the custom geom
into a geom plotly understands.
In the link above, the authors provide an example for geom_xspline
specifically but their method and code don’t work unfortunately.

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

No branches or pull requests

1 participant