我正在基础 R 中构建一个简单的热图。这是我的矩阵:
stleft = matrix(
c(0,5,5,2,6,8,4,6,9),
nrow=3,
ncol=3)
colnames(stleft) <- c("Narrow","Wide", "Wider")
rownames(stleft) <- c("Person", "Object","Bare")
stleft
Run Code Online (Sandbox Code Playgroud)
矩阵如下所示:
> stleft
Narrow Wide Wider
Person 0 2 4
Object 5 6 6
Bare 5 8 9
Run Code Online (Sandbox Code Playgroud)
要构建热图,我只需运行:
heatmap(stleft, Colv = NA, Rowv = NA, scale = "none")
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,“0”(对应于窄/人单元格)显示为深红色,而“9”(对应于更宽/裸单元格)显示为浅黄色。
如何“翻转”这个范围,使“0”以浅色显示,“9”以深色显示?
为什么图像被截断了?它在 RStudio 绘图面板中显示为截断的,并且以截断的方式保存。我尝试放大 R Studio 中的绘图面板,但无济于事。
heatmap()( 和image())heat.colors()默认用于生成颜色。如果您愿意,您可以提供自己的颜色,例如。通过使用heat.colors(),正好相反。
par(oma=c(3, 0, 0, 3))
col <- rev(heat.colors(999))
heatmap(stleft, Colv = NA, Rowv = NA, scale = "none", col = col)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4205 次 |
| 最近记录: |