I am aware of this thread - How to show matrix values on Levelplot
and this thread - Showing data values on levelplot in R
that ask similar questions. But I don't quite see how I can adapt the code to what I am trying.
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.
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?
Example data:
#Matrix1
M1 <- matrix(0, nrow=5, ncol=5)
M1[upper.tri(M1, diag = FALSE)]<-1
M1
#Matrix2
M2<-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])