我使用該R腳本:熱火地圖GGPLOT2
tableau <- read.table(
text =
"Net B C D E.(e) F.(f)
a 1.88 0.15 0.60 10.00 90.00
b 2.05 0.23 0.51 55.00 80.00
c 2.09 0.29 0.40 58.00 88.00
d 2.07 0.52 0.36 80.00 84.00
e 2.13 0.30 0.27 7.00 90.00",
header = TRUE)
library(plyr)
library(reshape)
library(ggplot2)
library(scales)
tableau.m <- melt(tableau)
tableau.m <- ddply(tableau.m, .(variable), transform, rescale = rescale(value))
(p <- ggplot(tableau.m, aes(variable, Net)) +
geom_tile(aes(fill = rescale), colour = "white") +
scale_fill_gradient(low = "white", high = "steelblue"))
base_size <- 9
p + theme_grey(base_size = base_size) +
labs(x = "", y = "") + scale_x_discrete(expand = c(0, 0)) +
scale_y_discrete(expand = c(0, 0)) +
theme(legend.position = "none", axis.ticks = element_blank(),
axis.text.x = element_text(size = base_size * 0.8, angle = 0,
hjust = 0, colour = "grey50"))
tableau.s <- ddply(tableau.m, .(variable), transform, rescale = scale(value))
last_plot() %+% tableau.s
我得到這個情節:
如果深藍色意味着更高的價值和白色意味着更低的值。
如何,如果可能的話,我可以改變這個代碼,以便:
- 從表中的值顯示在矩陣圖的相應單元?
- 熱圖的範圍不是在整個矩陣上計算,而是針對每列計算。因此,對於每個類別:B,C,D,E(e)和F(f),白色表示該列的較低值,而較深的藍色表示該列的較高值?
謝謝!
嗨@ eipi10,我意識到第一列的縮放方式應該與其他方法相反。也就是說,1.88應該是最黑的,而2.13應該是白的。是否有一種方法可以僅反轉一列的縮放比例? (我應該問這個新的問題嗎?) – Rodolphe
我其實去了,並問了一個新的問題... http://stackoverflow.com/questions/30078074/rescaling-with-plyr-ddply-in-r 乾杯! – Rodolphe