[英]How do I create heatmap matrix in R?
CSV文件圖像有人知道R代碼可以將此CSV轉換為熱圖矩陣嗎? 我希望最常用的構造是深紅色,而只使用一次的構造幾乎是白色。 任何幫助將非常感激。
我試過了:
heat <- read.csv("formations.csv", header = TRUE, sep = ",")
m <- as.matrix(heat[, -1])
rownames(m) <- heat$Formation
heatmap(m)
library(ggplot2)
library(reshape2)
d <- melt(d)
plt <- ggplot(data = d, aes(x = Formation, y = variable, fill = value))
plt <- plt + geom_tile() + scale_fill_gradient2(low ='white', high = 'red')
plt + theme_minimal()
d <- structure(list(Formation = structure(c(7L, 8L, 4L, 6L, 9L, 1L,
2L, 5L, 10L, 3L, 7L, 8L, 4L, 6L, 9L, 1L, 2L, 5L, 10L, 3L, 7L,
8L, 4L, 6L, 9L, 1L, 2L, 5L, 10L, 3L, 7L, 8L, 4L, 6L, 9L, 1L,
2L, 5L, 10L, 3L, 7L, 8L, 4L, 6L, 9L, 1L, 2L, 5L, 10L, 3L, 7L,
8L, 4L, 6L, 9L, 1L, 2L, 5L, 10L, 3L),
.Label = c("3-4-1-2", "3-4-2-1", "3-5-1-1", "3-5-2",
"4-1-2-1-2", "4-1-4-1", "4-2-3-1", "4-3-3", "4-4-2",
"5-3-2"), class = "factor"),
variable = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L, 6L),
.Label = c("13/14", "114/15", "115/16", "116/17", "117/18",
"118/19"), class = "factor"),
value = c(33, 5, 0, 0, 0, 0, 0, 0, 0, 0, 38, 0, 0, 0, 0,
0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 18, 17, 1,
1, 1, 0, 0, 0, 0, 0, 22, 10, 0, 0, 0, 3, 1, 1, 1, 0, 0, 6,
0, 0, 0, 0, 0, 0, 1, 1)),
row.names = c(NA, -60L),
.Names = c("Formation", "variable", "value"), class = "data.frame")
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.