0

I have created following heatmap of days in the week and hours in a day;

enter image description here

This is table of values, from which was the map created;

           0    1    2    3    4    5    6    7    8    9   10   11   12   13
nedeľa   2028 1236 1019  838  607  461  478  483  615  864  884  787 1192  789
piatok   1873  932  743  560  473  602  839 1203 1268 1286  938  822 1207  857
pondelok 1900  825  712  527  415  542  772 1123 1323 1235  971  737 1129  824
sobota   2050 1267  985  836  652  508  541  650  858 1039  946  789 1204  767
streda   1814  790  619  469  396  561  862 1140 1329 1237  947  763 1225  804
štvrtok  1856  816  696  508  400  534  799 1135 1298 1301  932  731 1093  752
utorok   1691  777  603  464  414  520  845 1118 1175 1174  948  786 1108  762

           14   15   16   17   18   19   20   21   22   23
nedeľa    959 1037 1083 1160 1389 1342 1706 1696 2079 1584
piatok    937 1140 1165 1318 1623 1652 1736 1881 2308 1921
pondelok  958 1059 1136 1252 1518 1503 1622 1815 2009 1490
sobota    963 1086 1055 1084 1348 1390 1570 1702 2078 1750
streda    863 1075 1076 1289 1580 1507 1718 1748 2093 1511
štvrtok   831 1044 1131 1258 1510 1537 1668 1776 2134 1579
utorok    908 1071 1090 1274 1553 1496 1696 1816 2044 1458

I wonder if there is some easy and elegant way how to swap color range, so that high values are represented by red color and other way around.

I've used this function;

heatmap (myMatrix, Colv=NA, Rowv=NA)
Ivan Horňák
  • 25
  • 1
  • 7
  • It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. The way you have shared your data isn't very reproducible (we can't just copy/paste that into R). Try sharing a `dput()` instead as described in the provided link. Or just use sample data from the `?heatmap` help page – MrFlick Nov 28 '18 at 18:54

1 Answers1

3

The default colors for the heatmap function are actually set by the image() function and are

col=heat.colors(12)

If you want to reverse them, just use pass

heatmap(..., col=rev(heat.colors(12)))

where ... are the rest of the parameters you need to pass.

MrFlick
  • 195,160
  • 17
  • 277
  • 295