3

I am a complete newbie with R and please forgive me if this already has been asked a gazillion times. I am trying to make a heatmap using R, following this example, which are tsvs.

This is an example.

name sam1 sam2
a     0.2  0
b     0.1  0.05
c     0.3  0.06

Sorry, I can not post the graph that I get (because I am a newbie).

When the graph is made the scale is between 0 to 1 (the data is rescaled between 0 to 1 in heatmap), however I do not have any values bigger than 0.3 in my files, hence I want to know if it is possible to have a scale between 0 to 0.3 in heatmap. I am not sure if I am providing enough details here, please let me know if I need to put in some more details here.

basically I am using

a <- read.table(file = "name", sep ="\t", header =T) 

a.m <- melt(a)

a.m <- ddply(a.m, .(variable), transform,  rescale = rescale(value))

(p <- ggplot(a.m, aes(variable, transposons)) + 
      geom_tile(aes(fill = rescale), colour = "yellow") + 
      scale_fill_gradient(low = "yellow",  high = "darkgreen"))

Any help is most appreciated, thanks in advance.

Alpha
  • 807
  • 1
  • 10
  • 14
Amit
  • 129
  • 2
  • 7

1 Answers1

3

By default we have ?rescale

    rescale(x, to = c(0, 1), from = range(x, na.rm = TRUE))

That's why your values are between 0 and 1.Just specify min and max to ?rescale

a.m <- ddply(a.m, .(variable), transform,  
                    rescale = rescale(value,to=c(0,0.3))))
agstudy
  • 119,832
  • 17
  • 199
  • 261
  • @Amit you can check the answer if your are ok. – agstudy Dec 24 '12 at 09:49
  • made the graphs again on a small data set. For sure using your suggestion produces the scale between 0 to 0.3 in graph, but I do not see noticeable difference in the colors between the heatmap produced using your suggestion and the one made using default rescale option. – Amit Dec 24 '12 at 10:16
  • @Amit changing the scale don't change the colors. I think you need scale_fill_gradientn to get Smooth colour gradient between n colours. see this question http://stackoverflow.com/questions/14000232/2-color-heatmap-in-r-with-middle-color-anchored-to-a-specific-value/14000512#14000512 – agstudy Dec 24 '12 at 10:23