gpt4 book ai didi

r - 如何在 Levelplot 上显示矩阵值

转载 作者:行者123 更新时间:2023-12-04 16:31:55 27 4
gpt4 key购买 nike

我有一个矩阵数据 here ,我用 levelplot 将其可视化.情节放在下面。但我只是无法将值放入情节中,我的意思是我读了 this question ,但还是想不通。

我怎样才能做到这一点 ?谢谢。

最佳答案

您链接到的答案中的代码的问题在于,它仅在 levelplot 公式中的对象命名为 x 时才有效。 , y , 和 z .

这是一个示例,它使用更标准的习惯用法来处理传入自定义面板函数的参数,因此变得更普遍适用:

library("lattice")

## Example data
x <- seq(pi/4, 5*pi, length.out=10)
y <- seq(pi/4, 5*pi, length.out=10)
grid <- expand.grid(X=x, Y=y)
grid$Z <- runif(100, -1, 1)

## Write a panel function (after examining 'args(panel.levelplot) to see what
## will be being passed on to the panel function by levelplot())
myPanel <- function(x, y, z, ...) {
panel.levelplot(x,y,z,...)
panel.text(x, y, round(z,1))
}

## Try it out
levelplot(Z ~ X*Y, grid, panel = myPanel)

enter image description here

关于r - 如何在 Levelplot 上显示矩阵值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13895480/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com