Skip to content

ggMarginal() not implemented #2025

Closed
Closed

Description

@danton267

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')"

Activity

  1. cpsievert commented on Nov 1, 2021

    @cpsievert
    Collaborator

    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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions