I am producing levelplots from data that range between -35 and +35. This is a reduced sample data set and the code I am using:
# the libraries
library(raster)
library(rgdal)
library(rasterVis)
# reduced example data
i <-c(-2,0,0,-1,0,-1,5,0,-3,0,-2,6,0,-1,-3,0,5,0,-2,0,-1,0,0,0,0,-2,0,-1,0,0,0,0,0,0,0,-1,0,0,0,0,0,-1,0,0,-2,-1,-2,0,0,0,-1,-1,0,0,0,-1,-2,0,0,0,0,3,0,0,0,-1,0,0,0,0,-1,0,-2,-1,0,-3,-1,0,-2,-2)
# bringing the data into the right shape
A = matrix(i ,nrow=16,ncol=5,byrow = TRUE)
# matrix to raster
r<-raster(A)
# define the color range breaks
breaksList = seq(-40, 40, by = 5)
# the levelplot with the original axes, not reduced
levelplot(r,margin=FALSE,scales=list(x=list(at=c(0.041666667,0.125,0.208333333,0.291666667,0.375,0.458333333,0.541666667,0.625,0.708333333,0.791666667,0.875,0.958333333),
labels=c("J","F","M","A","M","J","J","A","S","O","N","D")),
y=list(at=c(0.03125,0.09375,0.15625,0.21875,0.28125,0.34375,0.40625,0.46875,0.53125,0.59375,0.65625,0.71875,0.78125,0.84375,0.90625,0.96875),
labels=c(2016:2001))),
col.regions= colorRampPalette(c("white", "black")),
colorkey=list(col= colorRampPalette(c("white", "black")),at=breaksList))
My problem is that there are empty cells (white in this case) in the graph, even though there are values for these cells (see image below). I copy/pasted this solution together from several posts on here, and I suspect there may be a problem with the color ranges, not the values. But I can't for the life of me figure it out. I couldn't find a solution anywhere, and would be grateful for some pointers.
Edit: The empty/white cells do not have the value as indicated by the legend. None of the data is below -31, still other graphs with full data set (n=192) have 50% white area.
The current resulting graph:
I found the problem and as suspected it was a problem with the coloring. By not adding the same at=
parameter, I colored the diagram differently from the legend.
col.regions= colorRampPalette(c("white", "black")),
should have been
col.regions= colorRampPalette(c("white", "black")),at=breaksList,