Formatting problems with Heatmap.2 function in gplots library - fields and axis

I created a heatmap in R using heatmap2 from the gplots package and I have terrible problems formatting the image for use in the report.

The image is the eigenvalues ​​of the small correlation matrix of wavelet coefficients, and I want to present the largest eigenvalues ​​with strong colors, such as red and the smallest, using soft yellow or the like. The color palette is not so much a problem as the presentation of colors. Yellow is currently the largest eigenvalue, so if possible, I want to reorder.

You can also rotate the legend similar to the first image below, I checked the help for such information, but all I can find is the rotation of the row and column labels?

Perfect legend

Since my data represents weekly data for every hour, how can I change the x-axis to show the next 12/24 hour vector: 12,24,36,48,60,72,84,96,108,120,132,144,156,168. I tried to set this using cexCol, but I got an error that cex.axis has the wrong length, and I don't see an argument in heatmap2 in this.

par(mfrow=c(1,1))
heatmap.2(eigenvalsCombined,
          trace = "none",
          dendrogram = "none",
          Rowv = NULL,
          Colv = NULL,
          density.info = "none",
          margin = c(5,7),
          main = expression(paste("Heatmap of Largest Eigenvalues ",
                                  lambda[1], 
                                  " Across 7 Wavelet Scales")),
          xlab = "Time Index (hours)",
          key = TRUE,
          lmat = rbind(c(2,3),c(4,1)),
          key.title = NA,
          key.xlab = "Eigenvalue Magnitude")

As you can see from my image below the main name, it is also cut off, I tried to play with the external and internal fields, but this also has no effect. When I use the zoom function in the plotter and blow up the image, the text appears, does this mean that my formatting is correct?

enter image description here

, , dput (evalsvalsCombined) google drive .

+4
2

.

# (1) Define column names of data matrix following your 12/24hr vector
clnames <- rep("",ncol(eigenvalsCombined))
sq <- seq(12,168,12)
clnames[sq] <- sq
colnames(eigenvalsCombined) <- clnames

# (2) Reverse your color map
rev.heat.colors <- function(n) rev(heat.colors(n)) 

library(gplots)
#par(mfrow=c(1,1))

heatmap.2(eigenvalsCombined,
          trace = "none",
          dendrogram = "none",
          Rowv = NULL,
          Colv = NULL,
          density.info = "none",
          margin = c(5,7),
          main = "",
          xlab = "Time Index (hours)",
          lmat = rbind(c(5,2,3),c(6,1,4)),
          lwid = c(0.2, 4, 1.1),
          lhei = c(0.5, 4),
          key = TRUE,
          key.xlab = "Eigenvalue Magnitude",
          col = "rev.heat.colors",
          cexCol=1.2)

# Add title to the plot
title(main=expression(paste("Heatmap of Largest Eigenvalues ",
           lambda[1],  " Across 7 Wavelet Scales")))

, :

enter image description here


heatmap.2, .
myheatmap2.r .
:

clnames <- rep("",ncol(eigenvalsCombined))
sq <- seq(12,168,12)
clnames[sq] <- sq
colnames(eigenvalsCombined) <- clnames   
rev.heat.colors <- function(n) rev(heat.colors(n))

library(gplots)
source("myheatmap2.r")
myheatmap.2(eigenvalsCombined,
          trace = "none",
          dendrogram = "none",
          Rowv = NULL,
          Colv = NULL,
          density.info = "none",
          margin = c(5,7),
          main = "",
          xlab = "Time Index (hours)",
          lmat = rbind(c(2,3,6),c(4,1,5)),
          lwid = c(0.8, 4, 0.5),
          lhei = c(0.5, 4),
          key = TRUE,
          key.title="",
          key.xlab = "Eigenvalue\n Magnitude",
          col = "rev.heat.colors",
          cexCol=1.2)

title(main=expression(paste("Heatmap of Largest Eigenvalues ",
           lambda[1],  " Across 7 Wavelet Scales")))

:

enter image description here

+2

image fields. gplots heatmap2 .

library(fields)

sq <- c("", seq(12,168, 12))

par(mar=c(3.1,5.1,4.1,7.1), xpd=TRUE)
image(t(eigenCombined), col = rev(heat.colors(100)), 
            xaxt="n", yaxt="n", bty="n", xlim=c(-0.15,1),
      main=expression(paste("Heatmap of Largest Eigenvalues ",
                                                    lambda[1], " Across 7 Wavelet Scales")))
axis(4, at = seq(0,1, length.out = 7), 
     labels = rownames(eigenCombined), lty = 0, las=2)

axis(1, at = seq(0,1, length.out = length(sq)), 
     labels = sq, lty = 0, las=2)

image.plot(t(eigenCombined), legend.only = TRUE,
           col = rev(heat.colors(100)), 
           smallplot = c(0.05,0.1, 0.1,0.85))

enter image description here

+4

Source: https://habr.com/ru/post/1681560/


All Articles