# ============================================================ # Tutorial on drawing a heatmap using ggplot2 # by Umer Zeeshan Ijaz (http://userweb.eng.gla.ac.uk/umer.ijaz) # ============================================================= abund_table<-read.csv("SPE_pitlatrine.csv",row.names=1,check.names=FALSE) # Transpose the data to have sample names on rows abund_table<-t(abund_table) # Convert to relative frequencies abund_table <- abund_table/rowSums(abund_table) library(reshape2) df<-melt(abund_table) colnames(df)<-c("Samples","Species","Value") library(plyr) library(scales) # We are going to apply transformation to our data to make it # easier on eyes #df<-ddply(df,.(Samples),transform,rescale=scale(Value)) df<-ddply(df,.(Samples),transform,rescale=sqrt(Value)) # Plot heatmap p <- ggplot(df, aes(Species, Samples)) + geom_tile(aes(fill = rescale),colour = "white") + scale_fill_gradient(low = "white",high = "steelblue")+ 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(angle = 90, hjust = 1,size=5),axis.text.y = element_text(size=5)) pdf("Heatmap.pdf") print(p) dev.off()