在 glm 图中手动控制轴刻度线标签

Manually control axes tick mark labels in glm plot

我正在使用 levelplot() 绘制 traitglm() 输出。轴标签是自动的。我想用自定义表达式替换每个刻度标签,即 'woo' 应该是 'Wood' 而 'XH' 应该是 'Grassland'。

此外,我怎样才能将图中的 'XH'、'XL''XO' 重新排序为 'XO'、'XL'、'XH'?

我用这段代码作图:

aSO        = max( abs(traitsglm) )
colortSO   = colorRampPalette(c("blue", "white", "red")) 
plot.4thSO = levelplot(t(as.matrix(traitsglm)), 
                       xlab = "Env", 
                       ylab = "Traits", 
                       col.regions = colortSO(100), 
                       at = seq(-aSO, aSO, length = 100),
                       scales = list(x = list(rot = 45)))
print(plot.4thSO)

输出如下所示:

非常感谢任何建议:

这是 traitsglm 的 dput():

> dput(traitsglm)
structure(c(0, 0, 0, 0, -0.0156616179765263, 0.0457475723683713, 
0, 0, 0.065063431709575, 0.0390952440996195, 0, -0.0194671501115163, 
0, -0.0234664518436303, 0, 0.0916078166850258, 0.0109256858453898, 
0, 0.0137149350117998, 0, -0.0227890851186177, 0, 0, 0.0419307281357592, 
0.0143375543423802, 0, 0, 0, -0.0470842266584843, -0.0154350203811271, 
0, 0.0167536127627214, 0, 0, 0, -0.0294763453032897, 0, 0, -0.0456185799682106, 
0.0207276137008492, 0, 0, 0, 0, 0, 0, 0.000971877948579576, 0.0141354127135407, 
0, 0, -0.0142399452642402, 0, 0, 0.0169159154100949, 0, 0, -0.0126555144059337, 
0, 0, -0.00956369894367865), .Dim = c(20L, 3L), .Dimnames = list(
    c("disan", "disba", "diszo", "frube", "fruca", "frudr", "frufo", 
    "frule", "frunu", "frusy", "pgt", "pola", "polb", "polf", 
    "poli", "polw", "polx", "hei", "see", "woo"), c("XH", "XL", 
    "XO")))

一种可能的方法是在将矩阵传递给 levelplot() 之前对矩阵进行更改。

原文:

> traitsglm
               XH          XL            XO
disan  0.00000000 -0.02278909  0.0000000000
disba  0.00000000  0.00000000  0.0000000000
diszo  0.00000000  0.00000000  0.0000000000
frube  0.00000000  0.04193073  0.0000000000
fruca -0.01566162  0.01433755  0.0000000000
frudr  0.04574757  0.00000000  0.0000000000
frufo  0.00000000  0.00000000  0.0009718779
frule  0.00000000  0.00000000  0.0141354127
frunu  0.06506343 -0.04708423  0.0000000000
frusy  0.03909524 -0.01543502  0.0000000000
pgt    0.00000000  0.00000000 -0.0142399453
pola  -0.01946715  0.01675361  0.0000000000
polb   0.00000000  0.00000000  0.0000000000
polf  -0.02346645  0.00000000  0.0169159154
poli   0.00000000  0.00000000  0.0000000000
polw   0.09160782 -0.02947635  0.0000000000
polx   0.01092569  0.00000000 -0.0126555144
hei    0.00000000  0.00000000  0.0000000000
see    0.01371494 -0.04561858  0.0000000000
woo    0.00000000  0.02072761 -0.0095636989

修改版本:

# reverse x-axis order
tg <- traitsglm[,3:1] 

# change axis labels
attr(tg, "dimnames") <- list(
  c("Y1", "Y2", "Y3", "Y4", "Y5", "Y6", "Y7", "Y8", "Y9", "Y10",
    "Y11", "Y12", "Y13", "Y14", "Y15", "Y16", "Y17", "Y18", "Y19", "Wood"),
  c("X1", "X2", "Grassland") 
)

> tg
                X1          X2   Grassland
Y1    0.0000000000 -0.02278909  0.00000000
Y2    0.0000000000  0.00000000  0.00000000
Y3    0.0000000000  0.00000000  0.00000000
Y4    0.0000000000  0.04193073  0.00000000
Y5    0.0000000000  0.01433755 -0.01566162
Y6    0.0000000000  0.00000000  0.04574757
Y7    0.0009718779  0.00000000  0.00000000
Y8    0.0141354127  0.00000000  0.00000000
Y9    0.0000000000 -0.04708423  0.06506343
Y10   0.0000000000 -0.01543502  0.03909524
Y11  -0.0142399453  0.00000000  0.00000000
Y12   0.0000000000  0.01675361 -0.01946715
Y13   0.0000000000  0.00000000  0.00000000
Y14   0.0169159154  0.00000000 -0.02346645
Y15   0.0000000000  0.00000000  0.00000000
Y16   0.0000000000 -0.02947635  0.09160782
Y17  -0.0126555144  0.00000000  0.01092569
Y18   0.0000000000  0.00000000  0.00000000
Y19   0.0000000000 -0.04561858  0.01371494
Wood -0.0095636989  0.02072761  0.00000000

使用修改后的版本绘图:

library(lattice)

levelplot(t(as.matrix(tg)), 
          xlab = "Env", 
          ylab = "Traits", 
          col.regions = colortSO(100), 
          at = seq(-aSO, aSO, length = 100),
          scales = list(x = list(rot = 45)))