Home > Software engineering >  How interpret gray fields of grid produced by geom_tile?
How interpret gray fields of grid produced by geom_tile?

Time:12-25

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.

CodePudding user response:

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

CodePudding user response:

To answer your question in the comment:

The white boxes are simply the background of your plot. You can even see the grid lines. There are no values to plot there. NA values correspond to missing values in your data (having actually NA in a cell). Non existing values are not plotted.

  • Related