简体   繁体   中英

How do you manually set the heatmap.3/heatmap.2 color key?

I would like to display the range of my custom range of breaks :

breaks=seq(0, 1500, by=20)

to be shown in the color key. Is there a way to manually set the range of the color key?

heatmap.3(x, Rowv=T, Colv=F, col=mycol, RowSideColors=custom.annotation, scale="none", trace="none", dendrogram="row", breaks=breaks, cexRow=1, cexCol=1, key=T, main="Heatmap of raw seq reads", na.rm=TRUE)

EDIT:

It's a crude solution but I ended up changing the code itself. Modification shown between the asterisks.

if (key) {
          #    par(mar = c(5, 4, 2, 1), cex = 0.75)
          par(mar = c(5, 4, 2, 1), cex = 1)
          tmpbreaks <- breaks
          if (symkey) {
               max.raw <- max(abs(c(x, breaks)), na.rm = TRUE)
               min.raw <- -max.raw
               tmpbreaks[1] <- -max(abs(x), na.rm = TRUE)
               tmpbreaks[length(tmpbreaks)] <- max(abs(x), na.rm = TRUE)
          }
          else {
               #      min.raw <- min(x, na.rm = TRUE) # original code
               #      max.raw <- max(x, na.rm = TRUE) # original code
******************************
               if(length(breaks)>10){ # if custom breaks, then set min/max to min/max of breaks, etc
                    min.raw <- min(breaks, na.rm = TRUE)
                    max.raw <- max(breaks, na.rm=TRUE)
               }else{ # else, set min, max to min/max of values
                    min.raw <- min(x, na.rm = TRUE)
                    max.raw <- max(x, na.rm = TRUE)
               }
******************************

          }
if (key) {
          #    par(mar = c(5, 4, 2, 1), cex = 0.75)
          par(mar = c(5, 4, 2, 1), cex = 1)
          tmpbreaks <- breaks
          if (symkey) {
               max.raw <- max(abs(c(x, breaks)), na.rm = TRUE)
               min.raw <- -max.raw
               tmpbreaks[1] <- -max(abs(x), na.rm = TRUE)
               tmpbreaks[length(tmpbreaks)] <- max(abs(x), na.rm = TRUE)
          }
          else {
               #      min.raw <- min(x, na.rm = TRUE) # original code
               #      max.raw <- max(x, na.rm = TRUE) # original code
******************************
               if(length(breaks)>10){ # if custom breaks, then set min/max to min/max of breaks, etc
                    min.raw <- min(breaks, na.rm = TRUE)
                    max.raw <- max(breaks, na.rm=TRUE)
               }else{ # else, set min, max to min/max of values
                    min.raw <- min(x, na.rm = TRUE)
                    max.raw <- max(x, na.rm = TRUE)
               }
******************************

          }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM