Skip to content

ggMarginal() not implemented #2025

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

Closed
danton267 opened this issue Sep 26, 2021 · 1 comment
Closed

ggMarginal() not implemented #2025

danton267 opened this issue Sep 26, 2021 · 1 comment
Assignees
Labels

Comments

@danton267
Copy link
Member


library(plotly)
library(ggplot2)
library(ggExtra)

data(mpg)

p <- ggplot(mpg, aes(cty, hwy)) +
  geom_count() +
  geom_smooth(method="lm", se=F)

p <- ggMarginal(p, type = "histogram", fill="transparent")

ggplotly(p)

yields the following error:

Error in UseMethod("ggplotly", p) : 
  no applicable method for 'ggplotly' applied to an object of class "c('ggExtraPlot', 'gtable', 'gTree', 'grob', 'gDesc')"
@cpsievert
Copy link
Collaborator

cpsievert commented Nov 1, 2021

As with #2026, #2020, and #2028, {ggMarginal} is implemented on the {grid} level, so again, implementing a proper conversion would be a huge undertaking.

As a workaround, you can do something like:

library(plotly)

data(mpg)

p <- ggplot(mpg, aes(cty, hwy)) +
  geom_count() +
  geom_smooth(method="lm", se=F)

subplot(
  plot_ly(x = mpg$cty, color = I("black")),
  plotly_empty(),
  ggplotly(p),
  plot_ly(y = mpg$hwy, color = I("black")),
  nrows = 2, shareX = TRUE, shareY = TRUE,
  heights = c(0.2, 0.8),
  widths = c(0.8, 0.2),
  margin = 0.01
) %>%
  layout(showlegend = FALSE)

Screen Shot 2021-11-01 at 4 54 29 PM

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

No branches or pull requests

4 participants