使用有序列生成R中的热图和&行

时间:2014-04-09 12:20:33

标签: r heatmap

我想使用有序的6x6矩阵生成热图。这是我用过的代码:

mat_data <- data.matrix(data[,2:ncol(data)])  # transform column 2-7 into a matrix
rownames (data) <- c("1","2","3","4", "5", "6")
colnames (data) <- c("1","2","3","4", "5", "6")

png("..../trial.png",    # create PNG for the heat map        
width = 5*300,        # 5 x 300 pixels
height = 5*300,
res = 300,            # 300 pixels per inch
pointsize = 8)        # smaller font size

heatmap.2(mat_data, 
    cellnote = mat_data,  # same data set for cell labels
    main = "Trial",       # heat map title
    notecol="black",      # change font color of cell labels to black
    density.info="none",  # turns off density plot inside color legend
    trace="none",         # turns off trace lines inside the heat map
    margins =c(8,9),      # widens margins around plot
    col=my_palette,       # use on color palette defined earlier 
    dendrogram="none",    # no dendrogram
    Rowv = "FALSE",
    Colv="FALSE")         # turn off column clustering

dev.off()                 # close the PNG device

我想要排序1-6的行,并且列从左下角开始从上到下排序6-1,这样地图在(行,列)处配对1-1(6,1 ),2-1(6,2),3-1(6,3)......等等。

请协助如何更改订单,谢谢。

1 个答案:

答案 0 :(得分:1)

library(gplots)

#Create sample data
mat_data <- matrix(runif(36),6)  # transform column 2-7 into a matrix
rownames (mat_data) <- c("1","2","3","4", "5", "6")            ##mat_data, data doesn't exist
colnames (mat_data) <- c("1","2","3","4", "5", "6")

png("..../trial.png",    # create PNG for the heat map
width = 5*300,        # 5 x 300 pixels
height = 5*300,
res = 300,            # 300 pixels per inch
pointsize = 8)        # smaller font size



heatmap.2(mat_data[6:1,],  #Change row order
    cellnote = mat_data,  # same data set for cell labels
    main = "Trial",       # heat map title
    notecol="black",      # change font color of cell labels to black
    density.info="none",  # turns off density plot inside color legend
    trace="none",         # turns off trace lines inside the heat map
    margins =c(8,9),      # widens margins around plot
#    col=my_palette,       # use on color palette defined earlier - doesn't exist
    dendrogram="none",    # no dendrogram
    Rowv = "FALSE",
    Colv="FALSE")         # turn off column clustering

dev.off()                 # close the PNG device