尽管具有单元格值,但在水平图中显示为空的像素

时间:2018-03-25 14:44:04

标签: r graph levelplot

我正在从-35到+35之间的数据生成水平图。这是一个简化的样本数据集和我正在使用的代码:

# 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))

我的问题是图中有空单元格(本例中为白色),即使这些单元格有值(见下图)。 我从这里的几个帖子中复制/粘贴了这个解决方案,我怀疑颜色范围可能有问题,而不是值。但我不能为我的生活搞清楚。我无法在任何地方找到解决方案,并会感激一些指示。

编辑:空白/白色单元格没有图例所示的值。没有数据低于-31,其他具有完整数据集(n = 192)的图表具有50%的白色区域。

当前结果图:

enter image description here

1 个答案:

答案 0 :(得分:0)

我发现了问题并且怀疑这是着色问题。通过不添加相同的at=参数,我将图表与图例的颜色区别开来。

col.regions= colorRampPalette(c("white", "black")),

应该是

col.regions= colorRampPalette(c("white", "black")),at=breaksList,