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

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

Closed
bedantaguru opened this issue Jul 4, 2019 · 2 comments · Fixed by #2063
Closed

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

bedantaguru opened this issue Jul 4, 2019 · 2 comments · Fixed by #2063

Comments

@bedantaguru
Copy link

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

@bwu62
Copy link

bwu62 commented Jul 16, 2021

Running into same issue. Does anyone have a fix?

@wkumler
Copy link

wkumler commented Jul 21, 2021

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)

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

Successfully merging a pull request may close this issue.

4 participants