R 如何调整levelplot中的x和y标签?

R 如何调整levelplot中的x和y标签?,r,plot,axis,levelplot,R,Plot,Axis,Levelplot,这里我得到了一个示例,但我希望在两个轴上进行更多调整: library(lattice) library(RColorBrewer) m <- matrix(c(0,1,1,2,0,2,1,1,0),6,6) 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(le

这里我得到了一个示例,但我希望在两个轴上进行更多调整:

library(lattice)
library(RColorBrewer)
m <- matrix(c(0,1,1,2,0,2,1,1,0),6,6)
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'))

所以我想更改两个轴的标签,如:

B= c('a','b','c','d','e','f','g', 'h','i','j','k','l','m','n)

我希望这就是你想要的:

library(lattice)
library(RColorBrewer)
m <- matrix(c(0,1,1,2,0,2,1,1,0),6,6)
cols <- colorRampPalette(brewer.pal(6, "Spectral"))    
levelplot(m, 
      scales=list(
        x=list(at=1:6,labels=c("A","B","C","D","E","F")),
        y=list(at=1:6,labels=c("G","H","I","J","K","L"))
        ),
      col.regions = cols,
      xlab='X Label', ylab='Y Label')
您需要为每个轴添加一个列表。然后像以前一样指定标签。使用附加的“at”可以克服从0开始标签的问题

B= c('a','b','c','d','e','f','g', 'h','i','j','k','l','m','n)
library(lattice)
library(RColorBrewer)
m <- matrix(c(0,1,1,2,0,2,1,1,0),6,6)
cols <- colorRampPalette(brewer.pal(6, "Spectral"))    
levelplot(m, 
      scales=list(
        x=list(at=1:6,labels=c("A","B","C","D","E","F")),
        y=list(at=1:6,labels=c("G","H","I","J","K","L"))
        ),
      col.regions = cols,
      xlab='X Label', ylab='Y Label')