Heatmap acts different from tutorial

I’m trying to build a heat map base on this matrix

I follow the tutorial from this website: Heatmaps in R

I expect the higher value to have darker blue and lower values to have lighter blues. Here is my code:

trans_mat <- matrix(c(0.70778860,0.21891516,0.03838665,0.03490960,0.10412742,0.74698864,0.09025518,0.05862876,0.02924465,0.23094920,0.65959225,0.08021390,0.02523503,0.35502227,0.04453241,0.57521029), nrow = 4)

trans_mat <- t(trans_mat)
s <- 1:4

coords <- expand.grid(1:4,4:1)

anno_x <- coords$Var1
anno_y <- coords$Var2

vals <- unique(scales::rescale(c(trans_mat)))
o <- order(vals, decreasing = FALSE)
cols <- scales::col_numeric("Blues", domain = NULL)(vals)
colz <- setNames(data.frame(vals[o], cols[o]), NULL)

plot_ly(z = trans_mat, x = s, y = s, colorscale = colz, type = 'heatmap') %>%
  add_annotations(x = anno_x,
                  y = anno_y,
                  text = as.vector(t(round(trans_mat, 2))),
                  showarrow = FALSE)

The output looks like this:

The dark and light area seems to be somehow transposed.

I’ve checked cols by


It seems to be correct