test_df <- head(mtcars, 10)

Demo data

mat <- volcano[50:59, 50:59]
mat
#>       [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
#>  [1,]  120  118  116  113  111  110  110  109  106   105
#>  [2,]  119  117  115  113  110  110  109  107  106   105
#>  [3,]  117  115  113  111  110  109  109  107  106   105
#>  [4,]  115  113  112  110  109  108  108  106  105   105
#>  [5,]  113  111  110  109  108  108  107  106  105   104
#>  [6,]  110  110  109  108  107  107  106  105  105   104
#>  [7,]  110  110  108  107  106  108  105  105  104   104
#>  [8,]  110  109  107  106  105  107  105  104  104   104
#>  [9,]  110  108  106  105  105  106  105  104  104   103
#> [10,]  109  107  106  105  105  105  104  104  103   103

Highlighting a numeric vector using expressions

Highlight locations in a numeric vector which match an expression.

mat %>%
  hl_mat('green', .x < 105) %>%
  hl_mat('blue', .x > 115)
        [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    120  118  116  113  111  110  110  109  106   105
 [2,]    119  117  115  113  110  110  109  107  106   105
 [3,]    117  115  113  111  110  109  109  107  106   105
 [4,]    115  113  112  110  109  108  108  106  105   105
 [5,]    113  111  110  109  108  108  107  106  105   104
 [6,]    110  110  109  108  107  107  106  105  105   104
 [7,]    110  110  108  107  106  108  105  105  104   104
 [8,]    110  109  107  106  105  107  105  104  104   104
 [9,]    110  108  106  105  105  106  105  104  104   103
[10,]    109  107  106  105  105  105  104  104  103   103

Highlighting a numeric vector with a colour scale

Colour a numeric vector using a ggplot colour scale.

mat %>%
  hl_mat(scale_colour_viridis_c(option = 'A'))
        [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    120  118  116  113  111  110  110  109  106   105
 [2,]    119  117  115  113  110  110  109  107  106   105
 [3,]    117  115  113  111  110  109  109  107  106   105
 [4,]    115  113  112  110  109  108  108  106  105   105
 [5,]    113  111  110  109  108  108  107  106  105   104
 [6,]    110  110  109  108  107  107  106  105  105   104
 [7,]    110  110  108  107  106  108  105  105  104   104
 [8,]    110  109  107  106  105  107  105  104  104   104
 [9,]    110  108  106  105  105  106  105  104  104   103
[10,]    109  107  106  105  105  105  104  104  103   103

Highlighting a numeric vector with a colour scale and legend

mat %>%
  hl_mat(scale_colour_viridis_c(option = 'A'), show_legend = TRUE)
        [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    120  118  116  113  111  110  110  109  106   105
 [2,]    119  117  115  113  110  110  109  107  106   105
 [3,]    117  115  113  111  110  109  109  107  106   105
 [4,]    115  113  112  110  109  108  108  106  105   105
 [5,]    113  111  110  109  108  108  107  106  105   104
 [6,]    110  110  109  108  107  107  106  105  105   104
 [7,]    110  110  108  107  106  108  105  105  104   104
 [8,]    110  109  107  106  105  107  105  104  104   104
 [9,]    110  108  106  105  105  106  105  104  104   103
[10,]    109  107  106  105  105  105  104  104  103   103

legend:  104 106 108 110 112 114 116 118 120

Highlighting by location index

mat %>%
  hl_mat('blue', seq(1, 30, 2))
        [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    120  118  116  113  111  110  110  109  106   105
 [2,]    119  117  115  113  110  110  109  107  106   105
 [3,]    117  115  113  111  110  109  109  107  106   105
 [4,]    115  113  112  110  109  108  108  106  105   105
 [5,]    113  111  110  109  108  108  107  106  105   104
 [6,]    110  110  109  108  107  107  106  105  105   104
 [7,]    110  110  108  107  106  108  105  105  104   104
 [8,]    110  109  107  106  105  107  105  104  104   104
 [9,]    110  108  106  105  105  106  105  104  104   103
[10,]    109  107  106  105  105  105  104  104  103   103

Highlighting with alternating values

mat %>%
  hl_mat(rep(c('blue', 'green', 'red'), length.out = length(.)))
        [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
 [1,]    120  118  116  113  111  110  110  109  106   105
 [2,]    119  117  115  113  110  110  109  107  106   105
 [3,]    117  115  113  111  110  109  109  107  106   105
 [4,]    115  113  112  110  109  108  108  106  105   105
 [5,]    113  111  110  109  108  108  107  106  105   104
 [6,]    110  110  109  108  107  107  106  105  105   104
 [7,]    110  110  108  107  106  108  105  105  104   104
 [8,]    110  109  107  106  105  107  105  104  104   104
 [9,]    110  108  106  105  105  106  105  104  104   103
[10,]    109  107  106  105  105  105  104  104  103   103