我有兴趣将我的数据显示为一堆棋盘,并且正方形上的颜色编码反映了感兴趣的变量。使用groups
软件包中wireframe
命令中的lattice
参数,我能够生成一个堆叠的棋盘格框架。
gridlocs <- expand.grid(xval=1:4,
yval=1:4,
zval=1:3)
gridlocs$height <- c(rep(0,16), rep(50,16), rep(100,16))
gridlocs$colors <- rnorm(48, 7, 2)
testcols <- level.colors(gridlocs$colors,
at= do.breaks(range(gridlocs$colors), 12),
col.regions = heat.colors)
wireframe(height ~ xval + yval, groups=zval, data=gridlocs,
aspect=c(1,2), drape=FALSE,
col=testcols)
但是,由于wireframe
的默认着色方案是按z变量着色,所以我无法弄清楚如何独立于棋盘格的高度对正方形的背景着色。
下图是在图形软件中编辑的,反映了我可能希望该图看起来如何。棋盘的位置很好,我想知道如何根据数据框中的另一个变量({{1}以外)来填充正方形。
我也很高兴接受height
以外的软件包中的答案。