Last active
January 6, 2016 23:00
-
-
Save bluepnume/b750182b96b241d84f67 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ######################################################### | |
| ### A) Installing and loading required packages | |
| ######################################################### | |
| if (!require("gplots")) { | |
| install.packages("gplots", dependencies = TRUE, repos = "http://cran.us.r-project.org") | |
| library(gplots) | |
| } | |
| if (!require("RColorBrewer")) { | |
| install.packages("RColorBrewer", dependencies = TRUE, repos = "http://cran.us.r-project.org") | |
| library(RColorBrewer) | |
| } | |
| ######################################################### | |
| ### B) Reading in data and transform it into matrix format | |
| ######################################################### | |
| data <- read.csv("data.csv", comment.char="#") | |
| rnames <- data[,1] # assign labels in column 1 to "rnames" | |
| mat_data <- data.matrix(data[,2:ncol(data)]) # transform column 2-5 into a matrix | |
| rownames(mat_data) <- rnames # assign row names | |
| ######################################################### | |
| ### C) Customizing and plotting the heat map | |
| ######################################################### | |
| # creates a own color palette from red to green | |
| my_palette <- colorRampPalette(c("blue", "white", "red"))(n = 299) | |
| colors = c(seq(-200,-51,length=100),seq(-50,50,length=100),seq(51,650,length=100)) | |
| # creates a 5 x 5 inch image | |
| png("output.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, | |
| density.info=c("none"), | |
| key=F, | |
| cellnote = mat_data, # same data set for cell labels | |
| main = "Correlation", # heat map title | |
| notecol="black", # change font color of cell labels to black | |
| trace="none", # turns off trace lines inside the heat map | |
| margins =c(12,9), # widens margins around plot | |
| scale="none", | |
| symm=F,symkey=F,symbreaks=T, | |
| col=my_palette, # use on color palette defined earlier | |
| breaks = colors, | |
| dendrogram="none", # only draw a row dendrogram | |
| Colv="NA") # turn off column clustering | |
| dev.off() # close the PNG device |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment