Anjan Karpak
Anjan Karpak

Reputation: 15

Better Heatmap Visualization in R

I would like to have more shades to be present on my heatmap. Can anyone help me in it? I also added the summary of my matrix dataset.

enter image description here

The heatmap code that I used are as follows:

heatmap.2(matrix,
          Rowv = NA,
          main = "Cost Rankings Per DRG Definiion (Darker Shade = More Expensive) ", 
          xlab = "DRG Definition ID",
          ylab = "States", 
          Colv = NA, 
          scale = "column", 
          col = coul, 
          key = FALSE,
          margins = c(5,5), 
          cexRow = 0.9, 
          cexCol = 0.9,
          trace = "none")

The summary of the matrix dataset is as follows:

     > dput(head(matrix,4))
 matrix <- structure(c(156023.01, 934292.2, 565543.16, 859246.77, NA, 647281.97, 
 243467.03, 222016.05, 279984.88, 1785117.72, 1210217.08, 1738388.11, 
 277346.4, 3231424.9, 1784411.7, 2539940.3, 39613, 1146810.7, 
 529727.86, 986997.67, 29115.06, 1411979.35, 664273.27, 668479.85, 
 16767.96, 252979.91, 129183.95, 194504.99, 12812.02, 341007.53, 
 217723.31, 332953.97, 97131.88, 1128489.3, 282132.58, 668881.61, 
 20812.06, 429211.14, 256513.98, 811319.88, 17672.06, 778513.41, 
 376581.5, 883744.04, 66327.99, 1895388.92, 1139218.24, 1770164.66, 
 NA, 693016.78, 552007.41, 483426.1, NA, 307001.14, 219478.09, 
 235900.24, 420942.2, 3237765.7, 2324077.5, 3454459.9, 170549.8, 
 4283642.2, 1847497.8, 2111693.5, 80660.06, 2899429.18, 1182813.4, 
 868823.54, 21812, 1623755.28, 750785.96, 255470.21, 176095.6, 
 3042375.8, 2571992.4, 3845886.7, 212915.5, 4328484.6, 2354857.9, 
 2539054.7, 12795.97, 1428190.5, 845619.16, 739186.61, NA, 1088842.33, 
 276199.76, 354687.38, 14492.04, 1030805.76, 662401.33, 201840.91, 
 150853.3, 1650354.2, 1062210.5, 1191047.2, 93799.96, 1971933.46, 
 1004648.69, 942096.11, 53320.05, 607153.18, 536816.15, 675263.5, 
 449583.08, 1566839.43, 1216058.46, 1328317.78, 480714.9, 4432956, 
 2923127.9, 3734036.4, 30351.03, 1845418.4, 490566.1, 887689.86, 
 16899.87, 1417434.85, 537916.35, 957364.87, 119628.09, 554514.83, 
 503740.9, 735597.21, 60498.78, 1570577.33, 831183.79, 1284620.01, 
 69819, 1056405.42, 527309.68, 834961.1, 21140.01, 305148.39, 
 242055.17, 344205.12, 17556.07, 1373699.99, 575169.49, 946223.42, 
 120249.7, 3356762.9, 1830277.9, 1718258.6, 173518.6, 5074740.2, 
 2559276.8, 3491265, 243682.9, 4208010.3, 2177208.7, 2206312.8, 
 NA, 1164790.25, 734920.03, 385705.88, NA, 621862.56, 224061.47, 
 522187.25, NA, 420800.25, 142957.08, 89689.84, 68628, 1598802.4, 
 1007628.56, 1392052.55, 79459.91, 2167594.41, 1331532.99, 1787127.24, 
 80123.96, 1938321.88, 1367553.22, 1591825.51, 45644.95, 1846231.61, 
 845857.62, 799940.15, NA, 1743574.39, 483080.63, 488160.78, 22002.93, 
 1176770.78, 615141.82, 822419.76, 142209.15, 1812647.04, 786067.87, 
 1386309.67, 157990.4, 2685450.6, 1340283, 2853758.4, 97889.07, 
 1061083.38, 472556.81, 854388.81, 8565, 265924.46, 181199.06, 
 385888.2, NA, 567851.31, 392844.96, 565664.86, 203578.2, 1348414.4, 
 689989.1, 744118.2, 223589.1, 2988292, 1905895.2, 2254702.6, 
 NA, 460544.17, 140055.94, 184764.15, 44512, 958991.29, 734571.16, 
 1304339.5, 102656.06, 532474.07, 490331.13, 631933.61, 23193.11, 
 1322236.32, 415219.48, 577760.96, 289623.7, 6196698.2, 2691164.3, 
 3177288.4, 14978.88, 416428.11, 237793.89, 490808.12, 12587.9, 
 1015188.63, 427300.91, 718612.47, 27119.99, 794509.58, 313906.99, 
 629300.12, NA, 586226.22, 313110.32, 368281.97, 324313, 5000112.2, 
 2627556.1, 6328867.9, 101877.93, 1309521.19, 336968.01, 756488.94, 
 3443081, NA, NA, 26893877, 279713.2, 2260306.77, 715682.74, 1102111.17, 
 130221.96, 511929.23, 459850.58, 700773.81, 125233.9, 2377996.8, 
 1422292.5, 2330577.8, 12795.97, 518757.02, 515278.91, 618813.29, 
 163937.1, 1974857.3, 1676696.6, 3153277.4, NA, 405244.61, 238980.44, 
 278851, 135444.01, 981475.9, 526980.36, 764349.78, NA, 323890.23, 
 115054.89, 196663.15, NA, 444982.29, 335713.04, 313231.83, 235511.7, 
 3305858.6, 1296704.2, 2488698.1, NA, 580699.06, 449820.87, 410445.08, 
 34358.09, 1280896.67, 622115.43, 668290.15, 42067.62, 1362265.93, 
 748922.71, 1056568.71, 97188.08, 2612222.56, 1242745.79, 1366078.34, 
 117417.9, 2473766.6, 2048573.4, 1876080.3, 102559.6, 3149369, 
 2145636.7, 2414000.4, NA, 467014.79, 236454.04, 101899.06, 35960.04, 
 1760857.28, 1162040.99, 961624.76, 167320.9, 4204619.6, 1946831, 
 2103738, 32832.06, 878445, 625553.25, 1276837.06, NA, 356360.58, 
 293533.81, 567421.3, NA, 399723.77, 190391.18, 203457.08, 17524.08, 
 2140499.87, 741313.57, 593964.5, 502218.4, 5504568.4, 2482709.2, 
 4211229.8, 18708, 467092.41, 349188.9, 924921.44, 239522.08, 
 759303.93, 512292.32, 953998.01, 1158785.1, 11099233.1, 7970719.5, 
 13551004.4, 316024.5, 3121648.4, 1856544.4, 4538276.4, 20075.97, 
 738001.2, 368133.88, 57265.05, 60165.82, 908034.41, 594996, 720468.54, 
 24470.14, 547284.37, 312695.13, 85743.16, 19392.96, 878525.54, 
 397145.31, 351113.64, 92456.64, 2751536.61, 946755.13, 1783122.25, 
 NA, 778701.49, 277180.9, 721653.54), .Dim = c(4L, 100L), .Dimnames = 
 list(
c("AK", "AL", "AR", "AZ"), c("039 ", "057 ", "064 ", "065 ", 
"066 ", "069 ", "092 ", "100 ", "101 ", "175 ", "176 ", "177 ", 
"178 ", "180 ", "189 ", "190 ", "191 ", "192 ", "193 ", "194 ", 
"195 ", "202 ", "207 ", "208 ", "234 ", "243 ", "246 ", "247 ", 
"252 ", "253 ", "269 ", "280 ", "281 ", "282 ", "286 ", "287 ", 
"291 ", "292 ", "293 ", "300 ", "305 ", "308 ", "309 ", "310 ", 
"312 ", "313 ", "314 ", "329 ", "330 ", "331 ", "371 ", "372 ", 
"377 ", "378 ", "379 ", "389 ", "390 ", "391 ", "392 ", "393 ", 
"394 ", "418 ", "439 ", "460 ", "469 ", "470 ", "473 ", "480 ", 
"481 ", "482 ", "483 ", "536 ", "552 ", "563 ", "602 ", "603 ", 
"637 ", "638 ", "640 ", "641 ", "682 ", "683 ", "684 ", "689 ", 
"690 ", "698 ", "699 ", "811 ", "812 ", "853 ", "854 ", "870 ", 
"871 ", "872 ", "897 ", "917 ", "918 ", "948 ", "981 ", "982 "
)))

Upvotes: 0

Views: 104

Answers (2)

Gwang-Jin Kim
Gwang-Jin Kim

Reputation: 10010

With higher number for colors

library(RColorBrewer)
coul = brewer.pal(9, "BuPu")

 heatmap.2(matrix,
          Rowv = NA,
          main = "Cost Rankings Per DRG Definiion (Darker Shade = More Expensive) ", 
          xlab = "DRG Definition ID",
          ylab = "States", 
          Colv = NA, 
          scale = "column", 
          col = coul, 
          key = FALSE,
          margins = c(5,5), 
          cexRow = 0.9, 
          cexCol = 0.9,
          trace = "none")

hmap

Upvotes: 1

sai saran
sai saran

Reputation: 757

Try with normal code heatmap in R

heatmap(matrix, Colv = NA, Rowv = NA, scale="column")

enter image description here

Upvotes: 0

Related Questions