Skip to content

ggplotly fails to convert geom_tile element with no fill aesthetic. #1562

Description

@bedantaguru

The ggplotly fails to convert geom_tile element with no fill aesthetic.

Ref : stackoverflow question

library(ggplot2)

set.seed(1503)

df <- data.frame(x = rep(1:3, 3),
                 y = rep(1:3, 3),
                 z = sample(c("A","B"), 9,replace = TRUE), 
                 stringsAsFactors = F)

p1 <- ggplot(df)+
  geom_tile(aes(x=x,y=y, fill="grey"), color = "black")

p2 <- ggplot(df)+
  geom_tile(aes(x=x,y=y),fill="grey", color = "black")

class(plotly::ggplotly(p1))
#> [1] "plotly"     "htmlwidget"
class(plotly::ggplotly(p2))
#> Error in `[.data.frame`(g, , c("fill_plotlyDomain", "fill")): undefined columns selected

Details:
looks like the code is breaking here
https://github.com/ropensci/plotly/blob/2cc296de6f77515003378a64b9fbdc93298ab45b/R/layers2traces.R#L849

Activity

  1. bwu62 commented on Jul 16, 2021

    @bwu62

    Running into same issue. Does anyone have a fix?

  2. wkumler commented on Jul 21, 2021

    @wkumler
    Contributor

    Even more minimal example, showing how a missing fill aesthetic causes the issue. Maybe plotly should assume one, or fill invisibly if not provided? I.e. if no "fill" column exists in g then fill = "black", as ggplot does.

    library(plotly)
    
    df <- data.frame(x = rep(1:3, 3),
                     y = rep(1:3, 3),
                     z = sample(c("A","B"), 9,replace = TRUE))
    
    p1 <- ggplot(df) + geom_tile(aes(x=x,y=y, fill="whatever"))
    plotly::ggplotly(p1)
    
    p2 <- ggplot(df) + geom_tile(aes(x=x,y=y))
    plotly::ggplotly(p2)
    
  3. added a commit that references this issue on Nov 1, 2021
    ae7cd4b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions