rheatmapposthoctukey

how to draw a post-hoc probability heatmap using TukeyHSD


I was trying to analyze whether there is a blood pressure difference in different jobs. The number of jobs is exactly 30, and each job has about 50 subjects.

There is a significance blood pressure difference in those jobs by using one-way ANOVA, and post-hoc analysis using TukeyHSD was also performed.

AOV <- aov(Blood_pressure ~ Job, data = myData)
Tukey <- TukeyHSD(AOV)

TukeyHSD() yields the "difference" and "post-hoc p value" as a dataframe. I would like to know how to draw a post-hoc p-value heatmap using TukeyHSD in R.

here is a probability heatmap similar to what I'm expecting:

enter image description here

the heatmap should be triangle and showing different color with different post-hoc p value (<0.05, <0.01, <0.001 and NS).

below is the TukeyHSD result round to 5 digits

structure(c(0.74955, 0.35787, 0.31643, 0.16167, 0.08848, 0.095, 
0.86412, -0.305, 0.25917, 0.29955, 0.21921, 0.27833, -0.12722, 
0.23682, 0.88167, 0.4409, 0.14115, 0.245, -0.155, -0.04849, 0.37625, 
-0.155, 0.161, 0.125, 0.31187, 0.695, 0.45214, 0.36167, -0.39167, 
-0.43312, -0.58788, -0.66107, -0.65455, 0.11457, -1.05455, -0.49038, 
-0.45, -0.53033, -0.47121, -0.87677, -0.51273, 0.13212, -0.30865, 
-0.60839, -0.50455, -0.90455, -0.79804, -0.3733, -0.90455, -0.58855, 
-0.62455, -0.43768, -0.05455, -0.2974, -0.38788, -0.04144, -0.1962, 
-0.26939, -0.26287, 0.50625, -0.66287, -0.0987, -0.05833, -0.13866, 
-0.07954, -0.48509, -0.12105, 0.5238, 0.08303, -0.21672, -0.11287, 
-0.51287, -0.40636, 0.01838, -0.51287, -0.19687, -0.23287, -0.046, 
0.33713, 0.09427, 0.0038, -0.15476, -0.22795, -0.22143, 0.54769, 
-0.62143, -0.05726, -0.01688, -0.09722, -0.0381, -0.44365, -0.07961, 
0.56524, 0.12447, -0.17527, -0.07143, -0.47143, -0.36492, 0.05982, 
-0.47143, -0.15543, -0.19143, -0.00456, 0.37857, 0.13571, 0.04524, 
-0.07319, -0.06667, 0.70245, -0.46667, 0.0975, 0.13788, 0.05754, 
0.11667, -0.28889, 0.07515, 0.72, 0.27923, -0.02051, 0.08333, 
-0.31667, -0.21016, 0.21458, -0.31667, -0.00067, -0.03667, 0.1502, 
0.53333, 0.29048, 0.2, 0.00652, 0.77564, -0.39348, 0.17069, 0.21107, 
0.13073, 0.18986, -0.2157, 0.14834, 0.79319, 0.35242, 0.05268, 
0.15652, -0.24348, -0.13697, 0.28777, -0.24348, 0.07252, 0.03652, 
0.22339, 0.60652, 0.36366, 0.27319, 0.76912, -0.4, 0.16417, 0.20455, 
0.12421, 0.18333, -0.22222, 0.14182, 0.78667, 0.3459, 0.04615, 
0.15, -0.25, -0.14349, 0.28125, -0.25, 0.066, 0.03, 0.21687, 
0.6, 0.35714, 0.26667, -1.16912, -0.60495, -0.56457, -0.64491, 
-0.58578, -0.99134, -0.6273, 0.01755, -0.42322, -0.72296, -0.61912, 
-1.01912, -0.91261, -0.48787, -1.01912, -0.70312, -0.73912, -0.55225, 
-0.16912, -0.41197, -0.50245, 0.56417, 0.60455, 0.52421, 0.58333, 
0.17778, 0.54182, 1.18667, 0.7459, 0.44615, 0.55, 0.15, 0.25651, 
0.68125, 0.15, 0.466, 0.43, 0.61687, 1, 0.75714, 0.66667, 0.04038, 
-0.03996, 0.01917, -0.38639, -0.02235, 0.6225, 0.18173, -0.11801, 
-0.01417, -0.41417, -0.30766, 0.11708, -0.41417, -0.09817, -0.13417, 
0.0527, 0.43583, 0.19298, 0.1025, -0.08033, -0.02121, -0.42677, 
-0.06273, 0.58212, 0.14135, -0.15839, -0.05455, -0.45455, -0.34804, 
0.0767, -0.45455, -0.13855, -0.17455, 0.01232, 0.39545, 0.1526, 
0.06212, 0.05912, -0.34643, 0.01761, 0.66246, 0.22169, -0.07806, 
0.02579, -0.37421, -0.2677, 0.15704, -0.37421, -0.05821, -0.09421, 
0.09266, 0.47579, 0.23293, 0.14246, -0.40556, -0.04152, 0.60333, 
0.16257, -0.13718, -0.03333, -0.43333, -0.32683, 0.09792, -0.43333, 
-0.11733, -0.15333, 0.03354, 0.41667, 0.17381, 0.08333, 0.36404, 
1.00889, 0.56812, 0.26838, 0.37222, -0.02778, 0.07873, 0.50347, 
-0.02778, 0.28822, 0.25222, 0.43909, 0.82222, 0.57937, 0.48889, 
0.64485, 0.20408, -0.09566, 0.00818, -0.39182, -0.28531, 0.13943, 
-0.39182, -0.07582, -0.11182, 0.07505, 0.45818, 0.21532, 0.12485, 
-0.44077, -0.74051, -0.63667, -1.03667, -0.93016, -0.50542, -1.03667, 
-0.72067, -0.75667, -0.5698, -0.18667, -0.42952, -0.52, -0.29974, 
-0.1959, -0.5959, -0.48939, -0.06465, -0.5959, -0.2799, -0.3159, 
-0.12903, 0.2541, 0.01124, -0.07923, 0.10385, -0.29615, -0.18965, 
0.2351, -0.29615, 0.01985, -0.01615, 0.17072, 0.55385, 0.31099, 
0.22051, -0.4, -0.29349, 0.13125, -0.4, -0.084, -0.12, 0.06687, 
0.45, 0.20714, 0.11667, 0.10651, 0.53125, 0, 0.316, 0.28, 0.46687, 
0.85, 0.60714, 0.51667, 0.42474, -0.10651, 0.20949, 0.17349, 
0.36036, 0.74349, 0.50064, 0.41016, -0.53125, -0.21525, -0.25125, 
-0.06438, 0.31875, 0.07589, -0.01458, 0.316, 0.28, 0.46687, 0.85, 
0.60714, 0.51667, -0.036, 0.15087, 0.534, 0.29114, 0.20067, 0.18687, 
0.57, 0.32714, 0.23667, 0.38313, 0.14027, 0.0498, -0.24286, -0.33333, 
-0.09048, -0.26508, -0.39441, -0.4572, -0.59459, -0.79112, -1.70373, 
0.02875, -2.10373, -0.51764, -0.71508, -0.5528, -0.5696, -1.19418, 
-0.7778, 0.03374, -0.30267, -0.8356, -1.55373, -2.59049, -0.80755, 
-0.72524, -1.95373, -0.8775, -0.67444, -0.4344, -0.29929, -0.44006, 
-1.16696, -1.11064, -1.17438, -1.311, -1.51234, -2.4396, -0.69092, 
-2.8396, -1.23497, -1.44017, -1.26992, -1.28973, -1.9205, -1.5029, 
-0.68639, -1.01848, -1.55972, -2.2896, -3.32995, -1.52409, -1.45231, 
-2.6896, -1.60317, -1.39271, -1.15035, -1.02387, -1.16169, -1.90039, 
-0.33462, -0.43988, -0.78042, -1.91299, 0.07579, -2.31299, -0.40018, 
-0.77729, -0.42755, -0.5339, -1.2762, -0.84002, 0.06944, -0.11784, 
-0.88117, -1.76299, -2.84076, -0.65861, -0.81873, -2.16299, -0.94916, 
-0.58862, -0.25666, -0.35284, -0.43815, -1.34682, -0.45798, -0.7699, 
-1.88138, 0.08094, -2.28138, -0.40862, -0.75815, -0.43783, -0.52698, 
-1.25508, -0.82088, 0.07636, -0.14555, -0.86379, -1.73138, -2.80631, 
-0.67507, -0.79651, -2.13138, -0.92905, -0.59032, -0.28193, -0.33461, 
-0.42646, -1.31738, -0.59004, -1.7186, 0.26509, -2.1186, -0.21375, 
-0.58524, -0.24153, -0.34423, -1.08377, -0.64797, 0.2591, 0.06398, 
-0.68945, -1.5686, -2.64585, -0.47401, -0.62609, -1.9686, -0.75692, 
-0.40073, -0.07421, -0.16096, -0.24754, -1.15283, -1.70539, 0.1487, 
-2.10539, -0.3758, -0.64021, -0.40891, -0.45373, -1.12872, -0.70294, 
0.14961, -0.14568, -0.75309, -1.55539, -2.61558, -0.65792, -0.66538, 
-1.95539, -0.80708, -0.54167, -0.27874, -0.22041, -0.33722, -1.15226, 
-0.9205, -2.72215, -1.49728, -1.58051, -1.53499, -1.51253, -2.03753, 
-1.64323, -0.90919, -1.30026, -1.71765, -2.17215, -3.09404, -1.79671, 
-1.55457, -2.57215, -1.73273, -1.64214, -1.43052, -1.17357, -1.36128, 
-1.85316, -2.85873, -1.07696, -1.37006, -1.10898, -1.16746, -1.86183, 
-1.43279, -0.56413, -0.83825, -1.4802, -2.30873, -3.37517, -1.3548, 
-1.40036, -2.70873, -1.53849, -1.24751, -0.97211, -0.94884, -1.05647, 
-1.90104, -1.09728, -1.18051, -1.13499, -1.11253, -1.63753, -1.24323, 
-0.50919, -0.90026, -1.31765, -1.77215, -2.69404, -1.39671, -1.15457, 
-2.17215, -1.33273, -1.24214, -1.03052, -0.77357, -0.96128, -1.45316, 
-0.70421, -0.38775, -0.47474, -1.20085, -0.76694, 0.1286, -0.09728, 
-0.81011, -1.67561, -2.7501, -0.62567, -0.74213, -2.07561, -0.87498, 
-0.5392, -0.23344, -0.2808, -0.37357, -1.26193, -0.81992, -0.83973, 
-1.4705, -1.0529, -0.23639, -0.56848, -1.10972, -1.8396, -2.87995, 
-1.07409, -1.00231, -2.2396, -1.15317, -0.94271, -0.70035, -0.57387, 
-0.71169, -1.45039, -0.4272, -1.15632, -0.72197, 0.17613, -0.04367, 
-0.76476, -1.63341, -2.70855, -0.5738, -0.69784, -2.03341, -0.83022, 
-0.48996, -0.18018, -0.23564, -0.32702, -1.21924, -1.28811, -0.86003, 
0.00376, -0.27721, -0.90825, -1.72919, -2.79387, -0.79232, -0.82609, 
-2.12919, -0.96526, -0.68211, -0.41079, -0.3765, -0.48689, -1.3228, 
-0.67969, 0.12634, -0.2147, -0.73858, -1.44309, -2.47554, -0.71882, 
-0.62489, -1.84309, -0.77873, -0.58385, -0.3463, -0.20175, -0.3458, 
-1.05921, -0.17366, -0.50576, -1.04699, -1.77687, -2.81723, -1.01136, 
-0.93958, -2.17687, -1.09044, -0.87998, -0.63762, -0.51114, -0.64897, 
-1.38766, -0.88054, -1.51158, -2.33253, -3.3972, -1.39565, -1.42943, 
-2.73253, -1.5686, -1.28544, -1.01412, -0.97983, -1.09023, -1.92613, 
-0.95431, -1.84206, -2.92099, -0.7143, -0.89393, -2.24206, -1.02347, 
-0.65281, -0.30604, -0.42635, -0.50879, -1.42501, -1.65996, -2.70597, 
-0.86176, -0.80838, -2.05996, -0.9569, -0.73355, -0.48692, -0.37576, 
-0.50851, -1.26686, -3.24404, -1.94671, -1.70457, -2.72215, -1.88273, 
-1.79214, -1.58052, -1.32357, -1.51128, -2.00316, -2.22358, -1.93176, 
-2.84404, -2.11949, -2.06356, -1.85909, -1.56697, -1.76966, -2.16472, 
-0.41846, -1.75972, -0.54957, -0.19636, 0.12667, 0.04614, -0.04132, 
-0.94424, -2.36707, -1.31674, -1.13097, -0.89608, -0.74116, -0.8889, 
-1.58669, -1.48273, -1.39214, -1.18052, -0.92357, -1.11128, -1.60316, 
-0.83544, -0.5954, -0.46029, -0.60106, -1.32796, -0.15597, -0.1711, 
-0.27005, -1.14077, -0.30028, -0.38362, -1.29747, -1.08318, -1.83228, 
-1.52374, 1.76417, 1.11016, 1.09005, 0.91792, 0.96808, 1.89373, 
1.69949, 1.49373, 1.03598, 1.31417, 0.99122, 1.12626, 0.93973, 
1.25144, 1.7296, 1.18447, 1.1179, 2.04373, 2.28049, 0.71057, 
1.47774, 1.64373, 1.1995, 0.92444, 1.05814, 1.68929, 1.34434, 
1.89029, 0.32729, 0.30815, 0.13524, 0.19021, 1.13051, 0.92006, 
0.73051, 0.25421, 0.54017, 0.20925, 0.3473, 0.16696, 0.47744, 
0.95063, 0.40119, 0.34293, 1.28051, 1.52086, -0.07199, 0.70572, 
0.88051, 0.42608, 0.14362, 0.27499, 0.91478, 0.56689, 1.12463, 
0.25173, 0.04747, 0.24163, 1.38725, 0.93671, 0.98725, 0.20278, 
0.66064, 0.15023, 0.37482, 0.30601, 0.59791, 0.97815, 0.28389, 
0.44773, 1.53725, 1.81502, -0.15412, 0.85548, 1.13725, 0.55541, 
0.12287, 0.16465, 1.0271, 0.6267, 1.35441, 0.14845, 0.314, 1.43853, 
1.01444, 1.03853, 0.2941, 0.72438, 0.2434, 0.45078, 0.36777, 
0.66166, 1.05412, 0.39449, 0.51324, 1.58853, 1.86345, -0.05477, 
0.91615, 1.18853, 0.6182, 0.20747, 0.27282, 1.09175, 0.69789, 
1.40785, 0.44366, 1.58526, 1.13981, 1.18526, 0.40875, 0.861, 
0.35661, 0.57757, 0.50599, 0.79827, 1.1809, 0.49448, 0.64843, 
1.73526, 2.01251, 0.05369, 1.05526, 1.33526, 0.75559, 0.32739, 
0.37462, 1.22763, 0.82849, 1.55283, 1.71844, 1.40258, 1.31844, 
0.71717, 1.06234, 0.67037, 0.83344, 0.69732, 0.99962, 1.43677, 
0.85052, 0.85844, 1.86844, 2.12862, 0.38398, 1.24092, 1.46844, 
0.95212, 0.61472, 0.72552, 1.43345, 1.06454, 1.69864, 2.45873, 
1.92215, 1.82561, 1.9896, 1.78341, 1.87919, 1.59309, 1.92687, 
2.48253, 1.99206, 1.80996, 2.47215, 2.59404, 1.50972, 2.11707, 
2.07215, 1.86473, 1.70214, 1.86425, 2.37357, 2.07557, 2.38649, 
0.5205, -0.13294, 0.24092, -0.18084, -0.00411, -0.12085, 0.17819, 
0.59922, -0.00819, 0.03427, 1.0705, 1.33694, -0.47042, 0.42463, 
0.6705, 0.13225, -0.23073, -0.13239, 0.6106, 0.23253, 0.89614, 
2.22561, 2.3896, 2.18341, 2.27919, 1.99309, 2.32687, 2.88253, 
2.39206, 2.20996, 2.87215, 2.99404, 1.90972, 2.51707, 2.47215, 
2.26473, 2.10214, 2.26425, 2.77357, 2.47557, 2.78649, 0.78497, 
0.30783, 0.51307, 0.42807, 0.72224, 1.1164, 0.46074, 0.57408, 
1.64728, 1.92177, 0.01035, 0.97629, 1.24728, 0.67864, 0.27087, 
0.33884, 1.15247, 0.75952, 1.46693, 0.65925, 0.7973, 0.61696, 
0.92744, 1.40063, 0.85119, 0.79293, 1.73051, 1.97086, 0.37801, 
1.15572, 1.33051, 0.87608, 0.59362, 0.72499, 1.36478, 1.01689, 
1.57463, 0.54544, 0.46345, 0.75719, 1.14878, 0.48704, 0.60865, 
1.68499, 1.96013, 0.03839, 1.01191, 1.28499, 0.7138, 0.30154, 
0.3655, 1.18722, 0.79288, 1.50416, 0.477, 0.777, 1.20291, 0.60234, 
0.63389, 1.66253, 1.9272, 0.13866, 1.02193, 1.26253, 0.7306, 
0.37544, 0.47786, 1.20983, 0.83451, 1.48947, 1.40777, 1.89144, 
1.35094, 1.27533, 2.18753, 2.41999, 0.87628, 1.63184, 1.78753, 
1.35518, 1.08829, 1.22448, 1.8462, 1.50453, 2.03699, 1.46336, 
0.91392, 0.85566, 1.79323, 2.03359, 0.44074, 1.21844, 1.39323, 
0.9388, 0.65635, 0.78772, 1.4275, 1.07962, 1.63736, -0.001, 0.03056, 
1.05919, 1.32387, -0.46467, 0.41859, 0.65919, 0.12726, -0.22789, 
-0.12547, 0.6065, 0.23118, 0.88613, 0.35482, 1.45026, 1.72919, 
-0.26448, 0.76463, 1.05026, 0.46367, 0.02101, 0.04798, 0.93456, 
0.53128, 1.26654, 1.86765, 2.11366, 0.48246, 1.27858, 1.46765, 
0.9966, 0.70124, 0.82835, 1.48345, 1.13049, 1.70788, 2.44404, 
1.35972, 1.96707, 1.92215, 1.71473, 1.55214, 1.71425, 2.22357, 
1.92557, 2.23649, 2.4366, 2.99426, 2.84404, 2.75149, 2.62356, 
2.79282, 3.26697, 2.98394, 3.19806, 1.26794, 1.54671, 0.96855, 
0.54335, 0.59406, 1.44085, 1.04259, 1.76456, 1.30457, 0.88624, 
0.62847, 0.76732, 1.37866, 1.04069, 1.55752, 2.11473, 1.95214, 
2.11425, 2.62357, 2.32557, 2.63649, 0.76344, 0.89714, 1.52829, 
1.18334, 1.72929, 0.52971, 1.3111, 0.92434, 1.6141, 1.06654, 
0.66416, 1.39707, 0.59747, 1.16561, 1.34279, 0.56084, 0.99513, 
0.9996, 1, 1, 1, 0.032, 1, 0.99999, 1, 1, 0.99999, 1, 1, 0.02978, 
0.91917, 1, 1, 1, 1, 0.99999, 1, 1, 1, 0.99941, 0.68145, 0.98784, 
1, 0.96883, 0.93068, 0.3425, 0.44546, 0.99995, 1, 0.9222, 0.79136, 
0.99761, 0.62741, 0.94092, 0.27469, 0.9837, 1, 0.99884, 0.83576, 
1, 0.99993, 0.01294, 0.99998, 0.98785, 0.93586, 0.34234, 0.88577, 
1, 0.99999, 1, 1, 0.36349, 0.97939, 1, 0.00397, 0.99971, 0.99999, 
1, 0.99443, 1, 0.88744, 1, 0.00574, 0.99952, 1, 1, 1, 0, 1, 1, 
1, 0.8011, 1, 0.99275, 1, 1, 0.98658, 0.99934, 1, 0.00414, 0.99992, 
1, 1, 1, 1, 0.96743, 1, 0.00544, 0.997, 1, 1, 1, 0.00394, 1, 
1, 1, 0.99444, 1, 0.97747, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0.99996, 
1, 0, 5e-04, 1, 1, 1, 0.3876, 1, 1, 1, 1, 0.76408, 0.47061, 0.9721, 
1, 1, 0.00144, 1, 1, 1, 1, 1, 1, 1, 0.00156, 0.65619, 1, 1, 1, 
1, 1, 1, 1, 1, 0.99831, 0.57716, 0.98326, 1, 0.99754, 1, 1, 1, 
1, 1, 1, 1, 0.99669, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.99999, 1, 
1, 0.70188, 0.00066, 0.67584, 9e-05, 0.04572, 0.00713, 0.43889, 
1, 0.03884, 0.08634, 0.99995, 0.99894, 0, 0.97531, 0.90401, 0.27083, 
2e-05, 0.00036, 1, 0.83642, 0.99997, 0.99999, 0.99999, 1, 0.99999, 
1, 1, 0.67925, 0.99772, 1, 1, 1, 1, 0.99994, 1, 1, 1, 0.99992, 
0.9532, 0.99856, 1, 1, 1, 1, 0.99532, 1, 0.00097, 0.80888, 1, 
1, 1, 0.07442, 1, 1, 1, 0.99999, 1, 0.89595, 0.99999, 1, 1, 1, 
0.9996, 1, 0.6452, 1, 1, 1, 1, 0.99453, 1, 1, 1, 1, 1, 0.99962, 
1, 1, 1, 0.99912, 1, 0.00015, 0.28561, 1, 1, 1, 0.20112, 1, 1, 
1, 1, 0.99999, 0.76547, 0.99946, 1, 0.99715, 1, 0.04619, 0.99994, 
1, 1, 1, 0.67228, 1, 1, 1, 1, 1, 0.9803, 1, 1, 0.99998, 0.00667, 
0.60094, 1, 1, 1, 1, 0.99822, 1, 1, 1, 0.95755, 0.3696, 0.8633, 
1, 0.41242, 1, 1, 1, 1, 0.99981, 1, 1, 1, 1, 1, 0.99558, 1, 1, 
0.04859, 0.08088, 0.99992, 0.99863, 0, 0.96726, 0.8907, 0.25211, 
4e-05, 0.00065, 1, 0.81181, 0.99994, 0.9973, 1, 1, 0, 1, 0.99996, 
0.99991, 0.10484, 0.59105, 0.99993, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 0.91514, 0.9999, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1, 1, 1, 0.99998, 1, 1, 0.98881, 1, 1, 0.99607, 0, 0.02074, 0.12205, 
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0.99455, 0.99998, 1, 1, 1, 0.97387, 
1, 1, 0.96863, 0.4677, 0.96666, 1, 0.95618, 1, 1, 1, 1, 1), dim = c(406L, 
4L), dimnames = list(c("9-8", "17-8", "18-8", "19-8", "20-8", 
"23-8", "24-8", "25-8", "26-8", "28-8", "31-8", "34-8", "36-8", 
"37-8", "38-8", "43-8", "46-8", "48-8", "66-8", "71-8", "72-8", 
"76-8", "78-8", "83-8", "85-8", "86-8", "88-8", "96-8", "17-9", 
"18-9", "19-9", "20-9", "23-9", "24-9", "25-9", "26-9", "28-9", 
"31-9", "34-9", "36-9", "37-9", "38-9", "43-9", "46-9", "48-9", 
"66-9", "71-9", "72-9", "76-9", "78-9", "83-9", "85-9", "86-9", 
"88-9", "96-9", "18-17", "19-17", "20-17", "23-17", "24-17", 
"25-17", "26-17", "28-17", "31-17", "34-17", "36-17", "37-17", 
"38-17", "43-17", "46-17", "48-17", "66-17", "71-17", "72-17", 
"76-17", "78-17", "83-17", "85-17", "86-17", "88-17", "96-17", 
"19-18", "20-18", "23-18", "24-18", "25-18", "26-18", "28-18", 
"31-18", "34-18", "36-18", "37-18", "38-18", "43-18", "46-18", 
"48-18", "66-18", "71-18", "72-18", "76-18", "78-18", "83-18", 
"85-18", "86-18", "88-18", "96-18", "20-19", "23-19", "24-19", 
"25-19", "26-19", "28-19", "31-19", "34-19", "36-19", "37-19", 
"38-19", "43-19", "46-19", "48-19", "66-19", "71-19", "72-19", 
"76-19", "78-19", "83-19", "85-19", "86-19", "88-19", "96-19", 
"23-20", "24-20", "25-20", "26-20", "28-20", "31-20", "34-20", 
"36-20", "37-20", "38-20", "43-20", "46-20", "48-20", "66-20", 
"71-20", "72-20", "76-20", "78-20", "83-20", "85-20", "86-20", 
"88-20", "96-20", "24-23", "25-23", "26-23", "28-23", "31-23", 
"34-23", "36-23", "37-23", "38-23", "43-23", "46-23", "48-23", 
"66-23", "71-23", "72-23", "76-23", "78-23", "83-23", "85-23", 
"86-23", "88-23", "96-23", "25-24", "26-24", "28-24", "31-24", 
"34-24", "36-24", "37-24", "38-24", "43-24", "46-24", "48-24", 
"66-24", "71-24", "72-24", "76-24", "78-24", "83-24", "85-24", 
"86-24", "88-24", "96-24", "26-25", "28-25", "31-25", "34-25", 
"36-25", "37-25", "38-25", "43-25", "46-25", "48-25", "66-25", 
"71-25", "72-25", "76-25", "78-25", "83-25", "85-25", "86-25", 
"88-25", "96-25", "28-26", "31-26", "34-26", "36-26", "37-26", 
"38-26", "43-26", "46-26", "48-26", "66-26", "71-26", "72-26", 
"76-26", "78-26", "83-26", "85-26", "86-26", "88-26", "96-26", 
"31-28", "34-28", "36-28", "37-28", "38-28", "43-28", "46-28", 
"48-28", "66-28", "71-28", "72-28", "76-28", "78-28", "83-28", 
"85-28", "86-28", "88-28", "96-28", "34-31", "36-31", "37-31", 
"38-31", "43-31", "46-31", "48-31", "66-31", "71-31", "72-31", 
"76-31", "78-31", "83-31", "85-31", "86-31", "88-31", "96-31", 
"36-34", "37-34", "38-34", "43-34", "46-34", "48-34", "66-34", 
"71-34", "72-34", "76-34", "78-34", "83-34", "85-34", "86-34", 
"88-34", "96-34", "37-36", "38-36", "43-36", "46-36", "48-36", 
"66-36", "71-36", "72-36", "76-36", "78-36", "83-36", "85-36", 
"86-36", "88-36", "96-36", "38-37", "43-37", "46-37", "48-37", 
"66-37", "71-37", "72-37", "76-37", "78-37", "83-37", "85-37", 
"86-37", "88-37", "96-37", "43-38", "46-38", "48-38", "66-38", 
"71-38", "72-38", "76-38", "78-38", "83-38", "85-38", "86-38", 
"88-38", "96-38", "46-43", "48-43", "66-43", "71-43", "72-43", 
"76-43", "78-43", "83-43", "85-43", "86-43", "88-43", "96-43", 
"48-46", "66-46", "71-46", "72-46", "76-46", "78-46", "83-46", 
"85-46", "86-46", "88-46", "96-46", "66-48", "71-48", "72-48", 
"76-48", "78-48", "83-48", "85-48", "86-48", "88-48", "96-48", 
"71-66", "72-66", "76-66", "78-66", "83-66", "85-66", "86-66", 
"88-66", "96-66", "72-71", "76-71", "78-71", "83-71", "85-71", 
"86-71", "88-71", "96-71", "76-72", "78-72", "83-72", "85-72", 
"86-72", "88-72", "96-72", "78-76", "83-76", "85-76", "86-76", 
"88-76", "96-76", "83-78", "85-78", "86-78", "88-78", "96-78", 
"85-83", "86-83", "88-83", "96-83", "86-85", "88-85", "96-85", 
"88-86", "96-86", "96-88"), c("diff", "lwr", "upr", "p adj")))

Solution

  • You can use geom_tile from ggplot2 after creating the data frame from the output of TukeyHSD (the data you provided).

    library(dplyr)
    
    dd <- data.frame(p=Tukey[,4]) |>
      rownames_to_column() |>
      mutate(x=as.factor(as.numeric(sub('.*-(.*)', '\\1', rowname))),
             y=as.factor(as.numeric(sub('(.*)-.*', '\\1', rowname))),
             pValue=cut(p, breaks=c(-1, 0.0001, 0.001, 0.01, 0.05, 1), 
                           right=FALSE,
                        labels=c('<0.0001', '<0.001', '<0.01', '<0.05', 'NS'))) 
    
    library(ggplot2)
    
    ggplot(dd, aes(x, y, fill=pValue)) +
      geom_tile(col="grey50") +
      scale_fill_manual(values=c("purple3","blue","cyan","lightblue","grey70")) +
      scale_y_discrete(limits=rev) +
      theme_classic()
    

    enter image description here