title: Entering cell values from a matrix into a levelplot made in lattice in r
body: <p>I am aware of this thread - <a href="https://stackoverflow.com/questions/13895480/how-to-show-matrix-values-on-levelplot">How to show matrix values on Levelplot</a></p>
  
  <p>and this thread - <a href="https://stackoverflow.com/questions/6569666/showing-data-values-on-levelplot-in-r">Showing data values on levelplot in R</a></p>
  
  <p>that ask similar questions.  But I don't quite see how I can adapt the code to what I am trying.</p>
  
  <p>I have a matrix (M1) that I can make a levelplot from.  What I would like to do is add the respective value from each 'cell' in M1 to the corresponding 'cell' in the levelplot.  I have been trying with panel.levelplot but I just can't figure out how to define the variables x,y,z.</p>
  
  <p>A follow up question would be... if I can create a levelplot from matrix M1, but I want to add the values from another matrix (M2) of exactly the same size.  How can this be done?</p>
  
  <p>Example data:</p>
  
  <pre><code>#Matrix1
  M1 &lt;- matrix(0, nrow=5, ncol=5)
  M1[upper.tri(M1, diag = FALSE)]&lt;-1
  M1
  
  #Matrix2
  M2&lt;-matrix(sample.int(25, replace = TRUE), nrow = 5, ncol = 5)
  M2
  
  #This makes a levelplot but how to add the values from a) Matrix M1, b) Matrix M2
  levelplot(M1[1:ncol(M1),ncol(M1):1])
  </code></pre>