2016-11-23 221 views
2

我的数据是这样的:热图使用GGPLOT2

data1 <- read.table(text = "District Block IE  FE  AOE  CLE  CS 
A    A1 4.87 17.54 13.85 9.01 45.27 
       B    B1 8.19 20.83 14.59 7.04 50.65 
       C    C1 8.71 19.16 16.54 8.24 52.65 
       D    D1 2.43 11.77 11.51 6.96 32.67 
       E    E1 6.85 13.54 14.54 5.7  40.63 
       F    F1 7.02 19.96 13.96 3.82 44.76 
       G    G1 2.55 11.64 8.74 5.06 27.99 
       H    H1 9.81 20.2 12.62 5.95 48.58 
       I    I1 6.56 15.49 12.32 8.08 42.45 
       J    J1 9.47 22.86 25  22.73 80.06 
       K    K1 10.2 20.18 20.14 20.06 70.58 
       L    L1 9.52 14.86 16.95 18.23 59.56", header = TRUE) 

我已经创建了数据矩阵从dataframe.My最初的代码看起来像这样

row.names(data1)<-data1$Column1 

data1<-select(data1,-c(1)) 
data1<-data.matrix() 
data1_heatmap<-heatmap(data1,Rowv = NA,Colv = NA,col=heat.colors(256),scale = "none",margins = c(12,3)) 

每当我使用上面的代码,它绘制整张纸。

我有2个问题:

  1. 我需要显示其存在于所述数据矩阵中的单元格值。

  2. 另外我需要指定从IE到CS的每一列的颜色范围。例如,在IE列中少于4.87是红色的,6.56到6.85是橙色和绿色的大于8.17。所以基本上用户定义的范围为每列。

+1

这是什么都与'ggplot2'办? – Axeman

回答

0

与GGPLOT2试试这个(从原始数据1):

library(ggplot2) 
library(reshape2) 
row.names(data1)<-data1$Column1 
data1<-select(data1,-c(1)) 
data1 <- melt(data1, id='Block') 
data1$value <- cut(data1$value,breaks = c(-Inf,4.87, 6.56, 6.58, 8.17, 14, 19, 21, Inf),right = FALSE) # bin IE variable 
ggplot(data = data1, aes(x = Block, y = variable)) + 
    geom_tile(aes(fill = value), colour = "white") + 
    scale_fill_brewer(palette = "PRGn") 

enter image description here