Skip to content

geom_tile with only one possible value is grey #907

Open
@stanstrup

Description

@stanstrup

There seems to be a problem when a fill value in geom_tile only has one possible value.
Example below. You get grey instead of the color ggplot2 uses. This is an issue when you facet a geom_tile and one facet only contains one possible value. Then you get a completely grey tile instead of what color the value should have.

I'm guessing this has to do with scaling? Since you get NaN if you scale only identical values.

pp <- function (n,r=4) {
 x <- seq(-r*pi, r*pi, len=n)
 df <- expand.grid(x=x, y=x)
 df$r <- sqrt(df$x^2 + df$y^2)
  # df$z <- 1
  df$z <- c(1,2)
 df
}


p <- ggplot(pp(20), aes(x=x,y=y))
p <- p + geom_tile(aes(fill=z))

p
ggplotly(p)

ggplot:
image

plotly:
image

pp <- function (n,r=4) {
 x <- seq(-r*pi, r*pi, len=n)
 df <- expand.grid(x=x, y=x)
 df$r <- sqrt(df$x^2 + df$y^2)
   df$z <- 1
  # df$z <- c(1,2)
 df
}


p <- ggplot(pp(20), aes(x=x,y=y))
p <- p + geom_tile(aes(fill=z))

p
ggplotly(p)

ggplot:
image

plotly:
image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions