how to set different x&y label in levelplot?

假如想象 提交于 2020-01-06 03:24:14

问题


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

回答1:


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


来源:https://stackoverflow.com/questions/36239886/how-to-set-different-xy-label-in-levelplot

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!