Reputation: 1
I would like to generate a heat map using an ordered 6x6 matrix. This is the code I have used:
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
I want the rows ordered 1-6 across, and columns ordered 6-1 from top to bottom starting at the lower left hand box, such that the map is paired 1-1 at (row, column) (6,1), 2-1 at (6,2), 3-1 at (6,3)...etc
Kindly assist on how to change the order, thanks.
Upvotes: 0
Views: 1228
Reputation: 7951
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
Upvotes: 1