Search code examples
rggplot2geom-tile

How interpret gray fields of grid produced by geom_tile?


I have produced a grid using <geom_tile()> and I am at a loss with how to interpret the gray fields. The scaling is set at viridis, meaning, the colour of the field should vary between blue and yellow. So: How do I interpret gray fields or what type of value do they represent respectively. It further appears, that the number of gray fields changes, as I change the number of grid points. Below are two images: One represents the Hovmöllerplot with a high resolution grid (lots of latitude-time bands), whereas the other represents a Hovmöllerplot with a low resolution grid (few latitude-time bands).

Grid with low resolution

1

Grid with high resolution

2

I was expecting the colour of the grid points to range between blue and yellow or to be empty, in the case of NA.


Solution

  • Those are NA's. You could filter them out if you don't want them shown.

    df1 <- data.frame(x = 1:4, z = c(1:2, NA_real_, 4))
    
    ggplot(df1, aes(x, 1, fill = z)) +
      geom_tile() +
      scale_fill_viridis_c()
    

    enter image description here

    ggplot(subset(df1, !is.na(z)), aes(x, 1, fill = z)) +
      geom_tile() +
      scale_fill_viridis_c()
    

    enter image description here