title: How to resolve issue of an empty levelplot() in R?
body: <p>I am using levelplot() in R to generate a colored image of matrix (36 X 32). The matrix contains many NaN values in it. When I try to generate the levelplot using the following commands</p>
  
  <pre><code>range = c(815.4, 816.2)
  matpalette &lt;- colorRampPalette(c("blue", "black", "red"))(100)
  levelplot(t(m1),scales = list(draw = FALSE), col.regions = matpalette, xlab = "", ylab = "", at = seq(min(m1), max(m1), length = 100), main=main)
  </code></pre>
  
  <p>I get the following error message:</p>
  
  <pre><code>Error in seq.default(min(m1), max(m1), length = 100) : 'from' cannot be NA, NaN or infinite
  </code></pre>
  
  <p>This error is understood. Instead of using min(m1) and max(m1) in the levelplot(), when I try using the following:</p>
  
  <pre><code>levelplot(m1,scales = list(draw = FALSE), col.regions = matpalette, xlab = "", ylab = "", at = seq(range[1], range[2], length = 100), main=main)
  </code></pre>
  
  <p>I get an empty plot, just with the colorbar and with the range specified as tick values.</p>
  
  <p><img src="https://i.stack.imgur.com/inBDB.png" alt="enter image description here"></p>
  
  <p>What I need is a plot of the values in the matrix and the same colorbar and identical tick values as in the levelplot provided. Can anyone help me in this?</p>
  
  <p><strong># Variant 2</strong></p>
  
  <pre><code> s &lt;- seq(from=range[1], to=range[2], by=0.1)
  
   levelplot(t(m1), scales=list(tick.number=0), xlab=" ", ylab=" ", colorkey = list(at=s, labels=as.character(s)),col.regions = two.colors(n=256, start='blue', end='red', middle='black'), main=main)
  </code></pre>
  
  <p>The colorbar which I get is like this</p>
  
  <p><img src="https://i.stack.imgur.com/J5Q9O.png" alt="enter image description here"></p>
  
  <p>Note: Range used is different</p>