【问题标题】:How to adjust x and y lablels in levelplot?如何在 levelplot 中调整 x 和 y 标签?
【发布时间】:2019-01-17 15:19:18
【问题描述】:

这里有示例 (how to set different x&y label in 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(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', 'a','b','c','d','e','f','g') 

B= c('a','b','c','d','e','f','g')

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

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

【问题讨论】:

    标签: r plot axis levelplot


    【解决方案1】:

    我希望这就是您想要的:

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

    clickForResult

    您需要为每个轴添加一个列表。然后像以前一样分配标签。使用额外的“at”,您可以克服从 0 开始标签的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-08-01
      • 1970-01-01
      相关资源
      最近更新 更多