Switch to full style
Examples of R Scripting Language
Post a reply

Good looking HeatMap example in R using ggplot2

Tue Feb 09, 2016 6:40 am

In this example we show how to make a good looking heatmap using the ggplot2 R package. Following is the code example of using ggplot2 to plot the data as Heatmap.

RecallData <- read.csv("RankRecall_5_.csv",head=TRUE );
msg=paste(projectName,ApproachValue,': Recall rate for each   training data',sep='')


RecallData$month_name2 <- factor(RecallData$month_name,levels=c('1/2009' '2/2009' ,'3/2009''4/2009' ,'5/2009' ,'6/2009''7/2009' ,'8/2009','9/2009','10/2009','11/2009','12/2009'));
# here comes the RColorBrewer package, now if you ask me why did you choose this palette colour 
#I would say look at your battery charge indicator of your mobile for example your shaver,
# won't be red when gets low? and back to green when charged? This was the inspiration to choose this colour set.
ggplot(RecallDataaes(month_name2,distance)) +ylab("Training data by month")+xlab("Month/ Year") +
geom_tile(aes(fill= (recall)),colour="black") + guides(colour guide_legend(override.aes = list(size=0.3),ncol=1))+
scale_fill_gradient2(na.value "red"limits=c(0.350.63), midpoint=median(0.51),guide="colorbar",low =  ("red"), mid "yellow"high "green"name="Recall \n Rate")+
theme(legend.key.width=unit(0.2,"cm"),legend.margin=unit(-0.0,"cm"), legend.key.size=unit(0.4,"cm"),panel.background element_blank(),panel.grid.major element_blank(),panel.grid.minor element_blank(),plot.title element_text(size=4), plot.margin=unit(c(0,0,0,0),"mm"),axis.text.x=element_text(angle=-90,vjust0.0 ),axis.text element_text(colour "BLACK"),axis.text.x=element_text(colour="black"), text element_text(size=10))


The generated HeatMap from this snippet is using the traffic light colors. Theme information for this heatmap is controlled in theme function.

Rplot03.png (3.65 KiB) Viewed 7262 times

Post a reply
  Related Posts  to : Good looking HeatMap example in R using ggplot2
 ggplot2 for many boxplots in one figure example     -  
 Why is Using Gamification Good for Your Business?     -  
 here are 2 realy good books for sql     -  
 good books of jsp and jdbc     -  
 project in java.....plz suggest good ones........     -  
 need a good topic for project in java     -  
 How does one get good code for embeded video     -  
 Good looking selection box with image per option     -  
 Convert link and button to custom button with good style     -  

Topic Tags

R Analysis