我有一个大数据框。前 6 行的示例如下:
> temp
M1 M2 M3 M4 M5 M6
1 1 1 1 1 1 1
2 1 1 1 1 1 1
3 0 1 0 -1 1 0
4 1 1 1 1 1 1
5 0 0 0 -1 0 1
6 0 0 0 0 0 0
> dput(temp)
structure(list(M1 = c(1, 1, 0, 1, 0, 0), M2 = c(1, 1, 1, 1, 0,
0), M3 = c(1, 1, 0, 1, 0, 0), M4 = c(1, 1, -1, 1, -1, 0), M5 = c(1,
1, 1, 1, 0, 0), M6 = c(1, 1, 0, 1, 1, 0)), .Names = c("M1", "M2",
"M3", "M4", "M5", "M6"), row.names = c(NA, -6L), class = "data.frame")
Run Code Online (Sandbox Code Playgroud)
数据框只有值 -1、0 和 1。总行数为 2,156。我想做的是绘制一个“网格”格式,其中每行由 6 个正方形组成(每列一个)。然后为三个值中的每一个分配一个颜色(例如,红色、绿色、蓝色)。
我尝试使用 heatmap.2 来做到这一点(但我无法显示不同的方块)。
我尝试使用 ggplot2 和 geom_points() 来做到这一点,但无法找出最好的方法。
任何有关如何有效地做到这一点的帮助将不胜感激!
谢谢!
另外一个选择:
library(lattice)
temp <- as.matrix(temp)
levelplot(temp, col.regions= colorRampPalette(c("red","green","blue")))
Run Code Online (Sandbox Code Playgroud)
这将产生以下情节:
归档时间: |
|
查看次数: |
1680 次 |
最近记录: |