I am trying to customize the color key of my heaatmap. I was able to correct the position and the size of it (yay), but i am at a loss on how to change the values that are shown. The color key shows something called "colum Z scale", some default setting i presume.
I would like the color key to show the min and the max value of my data and some points in between. Unfortunately, this must be so easy that no one cares to explain it in any guide anywere i checked (yes, feeling quite dumb about it... ). I am quite sure that it should be possible to control this with the key.xtickfun function... but since i am new to R (and programming alltogehter) i cannot understand the documentation well enough to solve the problem on my own, so i am hoping to finde a little help here.
The code for my heatmap and the librarys is use are as follows:
library(ggplot2)
library(dplyr)
library(RColorBrewer)
library("gplots")
library(lattice)
heatmap.2(data_matrix
, dendrogram = "none"
, Rowv = FALSE
, Colv = FALSE
, scale = "column"
, trace = "none"
, margins = c(9,11)
, cexRow = 0.9
, cexCol = 0.9
, col = colors
, density.info = "none"
, keysize = 0.75
, lmat = rbind(c(3,4), c(2,1))
, key.xlab = "Wow, i can change the text! -_- Not what i was searching for"
, key.xtickfun=function() {
breaks <- parent.frame(n=1)$breaks
return(list(
at=parent.frame()$scale01(c(breaks[1],
breaks[length(breaks)])),
labels=c(as.character(breaks[1]),
as.character(breaks[length(breaks)]))
))
}
)
I tried to play around a bit with the variables in the function, but there are just too many possibilities and dependencies... it is like trying to catch the only fish in the ocean, using one tiny stick.... while beeing blindfolded.... So, if anyone can explain to me how to control the values of the Color key, i would be very thankful.
Best, S.