答案 0 :(得分:3)
编辑:我基本上回答了OP。
我花了一些时间来学习文本和图片在R中是如何工作的,还是不太了解它们,但这是解决问题的开始。
这些帖子对我帮助很大:
display a matrix, including the values, as a heatmap
以下几篇文章可能会彻底回答您的问题
How to show matrix values on Levelplot
你或许可以从下面的代码中提取想法,但我强调你看看这句话上方的主题。
编辑:以下代码可能就是您想要的内容!
library(lattice)
library(latticeExtra)
x <- c("A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3", "2")
y <- c("2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A" )
grid <- expand.grid(X= x, Y= y)
grid$Z <- c(
rep(0, 12), rep(1, 1),
rep(0, 11), rep(1, 1), rep(2, 1),
rep(0, 10), rep(1, 1), rep(2, 2),
rep(0, 9), rep(1, 1), rep(2, 3),
rep(0, 8), rep(1, 1), rep(2, 4),
rep(0, 7), rep(1, 1), rep(2, 5),
rep(0, 6), rep(1, 1), rep(2, 6),
rep(0, 5), rep(1, 1), rep(2, 7),
rep(0, 4), rep(1, 1), rep(2, 8),
rep(0, 3), rep(1, 1), rep(2, 9),
rep(0, 2), rep(1, 1), rep(2, 10),
rep(0, 1), rep(1, 1), rep(2, 11),
rep(3,1), rep(2, 12)
)
levelplot(Z ~ X*Y, data = grid) +
layer(panel.text(X, Y, paste(X, Y)), data = grid)
我会留给你弄清楚如何选择不同的颜色,并在&#34; s&#34;中插入不同的文字。和&#34; o&#34;附强>
尝试使用图片功能
m <- matrix(1:169, ncol=13)
colnames(m) <- paste("Card", 1:13, sep="")
rownames(m) <- paste("Card", 1:13, sep="")
image(1:ncol(m), 1:nrow(m), t(m))
axis(1, 1:ncol(m), colnames(m))
axis(2, 1:nrow(m), rownames(m))
x <- as.data.frame(c("A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3", "2"))
y <- as.data.frame(c("A", "K", "Q", "J", "10", "9", "8", "7", "6", "5", "4", "3", "2"))
z <- seq(1, 13, 1)
for (i in 1:13)
for (j in 1:13){
text(z[i], z[j], paste(x[i,], y[j,]))
}