Reputation: 486
I am using levelplot to plot a matrix. I need to change x and y labels. When I use the following piece of code, plot looks nice. However x and y labels are from 133 to 139 as opposed to 133..139 133...139. Can anyone help me fix it? (instead of huge matrix i am plotting, I ll give a sample matrix)
library(lattice)
library(RColorBrewer)
m <- matrix(c(0,1,1,2,0,2,1,1,0),6,6)
b <- c(seq(133,139),seq(133,139))
xy.labels <- b
cols <- colorRampPalette(brewer.pal(6, "Spectral"))
print(levelplot(m, scales = list(labels = xy.labels), col.regions = cols))
Upvotes: 2
Views: 1489
Reputation: 701
I think you can simply use the xlab
and ylab
options.
print(levelplot(m, scales = list(labels = xy.labels), col.regions = cols,
xlab='X Label', ylab='Y Label'))
The other labels could be changed as follows
B= c('a','b','c','d','e','f','g', 'a','b','c','d','e','f','g')
XY.labels=B
cols <- colorRampPalette(brewer.pal(6, "Spectral"))
print(levelplot(m, scales = list(labels = XY.labels), col.regions = cols,
xlab='X Label', ylab='Y Label'))
Upvotes: 2