[R] color heatmap according to value ranges

N.Hubner at ncmls.ru.nl N.Hubner at ncmls.ru.nl
Fri Feb 6 16:13:07 CET 2015


Probably the simplest thing there is, but I can't get it to work:



Example for my data:



a <- c(1,1,1,2,2,2,3,3,3)

b <- c(1,2,3,1,2,3,1,2,3)

c <- c(1,2,3,4,5,6,7,8,9)

df <- data.frame(cbind(a,b,c))



I create a heat map with c being the values:



ggplot(df, aes(df$a, df$b, fill = df$c)) + geom_raster()



problem:

The color coding is automatically a gradient. However, I would like to color in 4 fixed colors dependent on the value in c. For example:



if c<=2 color "darkblue"

if 2<c<=3 color "blue"

if 3<c<=5 color "lightblue"

if c>5 color "white"



In addition I would like to show a legend that illustrates this color coding.



It must be very easy, but I just can't figure it out. Only find commands that make gradients...



Thanks a lot in advance!




______________________________________________

Dr. Nina C. Hubner
scientist quantitative proteomics

Department of Molecular Biology, Radboud University Nijmegen, The Netherlands
e-mail: n.hubner at ncmls.ru.nl
tel: +31-24-3613655

Visiting address:
Department of Molecular Biology, RIMLS, 2nd floor
Geert Grooteplein 26/28
6525 GA Nijmegen
The Netherlands



The Radboud University Medical Centre is listed in the Commercial Register of the Chamber of Commerce under file number 41055629.

	[[alternative HTML version deleted]]



More information about the R-help mailing list