如何强制ggplot按照我们想要的顺序排列x轴或y轴?

时间:2015-03-28 09:49:46

标签: r ggplot2

我有一个数据框,第一列就像这样

    df<- structure(list(phenelzine = c(-0.0269, 0.0217, 0.4609, -0.0011, 
0.0016, -0.0334, 0.5159, 0.4687, -0.5715, -0.1466, 0.1096, 0.1006, 
-0.1021, 0.0093, -0.2616, 0.1496, 0.4463, -0.0833, 0.0573, 0.0602, 
0.1345, -0.0911, -0.1444, -0.0624, -0.2009, -0.0579, 0.1701, 
-0.161, -0.376, 0.1239, -0.1529, -0.1217, 0.2659, 0.1975, 0.0598, 
-0.1397, 0.1959, -0.0342, -0.0771, 0.0017, 0.0562, 0.0605, -0.0976, 
0.3257, -0.0385, -0.0687, 0.3087, 0.0992, -0.2253, -0.3171, -0.055, 
0.2071, -0.1928, -0.113, -0.2142), denatonium.benzoate = c(-0.1734, 
-0.2142, 0.2142, -0.1376, -0.0129, 0.0254, 0.06, 0.1768, 0.2295, 
0.1772, 0.1978, -0.0556, 0.0971, 0.0979, 0.2073, 0.061, 0.2782, 
-0.048, -0.0825, 0.1922, -0.0395, 0.1594, -0.2117, -0.0999, 5e-04, 
-0.0595, -0.2083, 0.1004, -0.1279, -0.0613, -0.0576, -0.0567, 
0.1006, -0.0213, -0.1109, 0.0313, 0.0641, -0.2919, -0.0119, 0.1644, 
-0.1197, -0.1138, 0.078, -0.2729, -0.022, -0.1864, -0.0709, 0.0211, 
0.0183, 0.0175, 0.1655, 0.0064, -0.0701, 0.0274, 0.1163), triamterene = c(-0.0253, 
0.2896, 0.1606, -0.086, -0.1886, 0.0355, 0.0552, 0.0733, 0.0131, 
0.6887, -0.0161, -0.3962, 0.1294, 0.0316, -0.1851, -0.1193, 0.0308, 
-0.1663, 0.0417, -0.0568, 0.1047, 0.0162, 0.3497, 0.0708, -0.0317, 
-0.1471, -0.1588, -0.4929, 0.078, 0.1263, -0.2024, -0.0021, -0.3611, 
-0.0494, -0.4211, -0.0226, 0.5045, -0.0757, 0.0328, -0.0198, 
-0.2622, 0.2297, -0.0454, 0.4094, 0.0826, -0.4326, 0.0316, 0.3048, 
-0.2047, 0.1124, -0.2369, 0.1803, -0.1735, 0.2399, -0.0509), 
    talampicillin = c(-0.1761, -0.0355, 0.0295, 0.1979, 0.0545, 
    0.0673, -0.0797, -0.1566, 0.0496, 0.2623, -0.197, 0.0192, 
    -0.2673, 0.0687, -0.0058, -0.4072, -0.06, -0.2315, 0.2532, 
    -0.0395, 0.0911, -0.1348, -0.018, 0.3084, 0.3751, 0.1659, 
    -0.1882, 0.1874, -0.0979, -0.0829, -0.1693, 0.0179, -0.0264, 
    0.1013, 0.4272, 0.1253, -0.0733, 0, 0.1552, -0.3395, -0.0738, 
    0, 0, -0.1746, -0.2039, 0.2907, 0.0363, 0.2168, -0.1428, 
    -0.2898, 0.0793, 0.349, -0.043, 0.1547, -0.0557), triamcinolone = c(0.0115, 
    0.3329, -0.0752, 0.2784, -0.5543, 0.0139, -0.6692, -0.4599, 
    -4e-04, 0.0115, 0.0624, -0.2127, 0.1339, 0.1186, -0.0732, 
    0.1033, -0.0672, 0.0038, -0.0445, -0.2484, 0.0075, 0.1113, 
    0.3911, 0.0205, -0.0126, -0.0763, 0.0073, 0.4081, -0.2826, 
    -0.0348, 0.0957, -0.0069, 0.0103, 0.0607, 0.7144, 0.0012, 
    0.0216, 0.1009, -0.0395, -0.0432, 0.08, -0.1039, -0.38, 0.0532, 
    -0.0404, 0.4977, 0.0735, -0.0793, -0.4312, 0.0332, -0.0964, 
    0.1067, -0.0468, 0.0052, 0.1366), sulfaphenazole = c(-0.0886, 
    0.1081, 0.2002, 0.0625, 0.0403, 0.0256, -0.0074, -0.0678, 
    -0.0393, 0.3201, 0.4213, -0.3058, -0.1228, 0.0797, 0.0591, 
    -0.0541, -0.0721, -0.1914, -0.3058, 0.4353, 0.176, -0.1903, 
    0.142, -0.078, 0.0747, -0.3066, 0.2954, -0.2864, 0.0823, 
    -0.2976, 0.0354, 0.1075, 0.0696, 0.0413, -0.1505, -0.0958, 
    0.0996, 0.3221, -0.0582, 0.0723, 0.016, -0.3852, 0.0542, 
    0.0229, 0.1946, -0.0557, -0.0675, -0.2177, 0.2971, 0.3417, 
    -0.4023, -0.2623, 0.0103, -0.3864, 0.591), procyclidine = c(0.03, 
    0.0372, 0.335, 0.1666, -0.0048, -0.1153, 0.1449, -0.0488, 
    0.1038, -0.0245, 0.1008, 0.0194, -0.0315, -0.0325, 0.0161, 
    0.0316, 0.19, -0.3043, -0.1044, 0.2325, -0.0602, 0.0076, 
    0.1493, -0.049, 0.0593, -0.0343, 0.0667, 0.1323, 0.2388, 
    0.0962, -0.2329, -0.2198, 0.0395, -0.0078, 0.1016, 0.03, 
    -0.1293, -0.0076, -0.1876, -0.2648, 0.0044, 0.0609, 0.0403, 
    -0.0914, -0.1242, -0.0627, 0.067, 0.0665, 0.1154, 0.286, 
    -0.2009, 0.2039, -0.0567, -0.0365, -0.0198), pentoxifylline = c(0, 
    0.3439, -0.0614, 0.0181, -0.0149, -0.0216, -0.1211, -0.1816, 
    -0.0204, 0.1023, -0.0059, -0.008, -0.1121, 0.2029, 0.052, 
    -0.0935, 0, 0.0595, 0.0271, -0.0482, 0.0246, -0.1369, 0.1106, 
    0.4988, -0.0599, 0.0021, -0.0233, 0.2809, 5e-04, -0.0204, 
    0.0586, 0.0278, 0.0246, 0.0534, 0.0165, -0.1816, -0.071, 
    -0.0296, -0.1173, 0.0814, -0.0672, 0.0946, -0.2164, 0.0299, 
    -0.1341, 0.0439, 0.1124, 0.0125, -0.4091, -0.1134, 0.0098, 
    0.1957, 0.0044, 0.0922, 0.1851), suloctidil = c(-0.0772, 
    -0.1651, -0.0543, -0.037, 0.2182, -0.1884, 0.1866, 0.2013, 
    -0.3388, 0.0493, 0.0223, 0.3441, 0.0887, -0.1477, -0.0719, 
    -0.029, -0.0162, 0.0602, 0.1497, -0.0699, 0.1472, 0.3213, 
    -0.1266, 0.9143, 0.072, 0.4574, -0.1897, -0.7059, 0.3822, 
    -0.1055, -0.0744, 0.179, -0.5096, -0.4966, -0.8764, -0.3903, 
    0.174, 0.2181, -0.122, -0.0097, -0.2281, -0.1387, -0.0506, 
    0.1179, 0.1911, -0.9006, -0.0161, -0.2298, 0.1777, -0.1341, 
    -0.0264, -0.3478, -0.188, 0.035, 0.0441), etacrynic.acid = c(0.1017, 
    -0.4238, -0.0089, -0.1116, 0.1265, -0.0529, -0.121, -0.0243, 
    -0.0033, -1e-04, 0.0952, 0.4075, -0.3078, 0.1265, -0.0612, 
    -0.1239, 0.0381, 0.0491, 0.1062, -0.0398, 0.2044, 0.0341, 
    -0.0654, 0.2705, 0.0408, 0.0064, -0.0858, -0.19, -0.4934, 
    -0.0524, 2e-04, -0.1496, -0.1018, -0.3303, -0.665, -0.6764, 
    0, -0.0248, -0.091, 0.052, -0.0327, 0.2288, 0.8196, -0.1288, 
    0.038, -0.4468, 0.0013, -0.2137, 0.6752, 0.1275, 0.0198, 
    0.1209, -0.0735, 1e-04, -0.0706), diphenylpyraline = c(0.0495, 
    -0.1318, -0.0723, -0.0485, 0.0175, -0.1585, 0.0054, 0.0565, 
    -0.0637, 0.0366, 0.0155, 0.1003, -0.11, -0.129, 0.0673, -0.0519, 
    0.0284, -0.1663, 0.0224, -0.1806, -0.1265, 0.1559, -0.1337, 
    -0.0892, 0.08, -0.2713, -0.0064, -0.0193, -0.2862, -0.0627, 
    0.1242, 0.0607, -0.1815, -0.107, 0.038, -0.0171, 0.1978, 
    0.1513, -0.1016, -0.086, -0.0019, 0.042, -0.0073, -0.0751, 
    -0.0388, 0.0844, -0.0678, -0.0556, 0.1765, -0.0377, -0.0143, 
    0.3352, 0.0206, 0.1197, -0.1429), carbenoxolone = c(0.0769, 
    0.0987, 0.1992, -0.016, -0.0276, 0.2596, -0.0086, -0.0038, 
    -0.2432, -0.0237, 0.0696, -0.1436, 0.1942, -0.0411, -0.0948, 
    0.2645, -0.114, -0.0887, -0.6041, 0.0061, 0.0875, -0.1449, 
    -0.1735, -0.0606, -0.0785, 0.3483, 0.1196, 0.2659, 0.0614, 
    -0.1372, 0.1543, 0.0434, -0.0253, -0.0028, 0.0956, 0.3397, 
    -0.0771, 0.2627, -0.0028, 0.1337, 0.0046, -0.0757, -0.0112, 
    -0.084, 0.0312, 0.0935, -0.0709, 0.0829, -0.1061, -0.1504, 
    0.0122, 6e-04, 0.3138, 0.0632, 0.1019), arecoline = c(0.0185, 
    0.1999, -0.0313, -0.1868, -0.0626, 0.0298, 0.03, 0, -0.2209, 
    0.0101, -0.0693, -0.1656, -0.1048, 0.2098, 0.0393, -0.1354, 
    0.0328, -0.0311, -0.1967, -0.2653, 0.204, 0.1737, 0.36, -0.1034, 
    -0.3326, 0.0613, -0.2044, 0.1967, 0.0042, 0.2329, 0.2409, 
    -0.0335, 0.0068, 0.5101, 0.2002, 0.1867, 0.2134, -0.1072, 
    0.0854, 0.2414, -0.0653, 0.3851, 0.1358, -0.0102, 0.0268, 
    0.2497, -0.1376, 0.1798, 0.0427, 0.1593, -0.29, 0.0343, 0.2249, 
    -0.1301, -0.0987), chenodeoxycholic.acid = c(-0.0825, 0.2098, 
    -0.0911, -0.0287, 0.0473, 0.1348, -0.06, -0.0285, -0.1473, 
    -0.0162, -0.0863, 0.0652, -0.0256, 0.1345, -0.1175, -0.0141, 
    0.2985, 0.2963, 0.1925, -0.212, -0.2106, -0.1128, -0.3121, 
    0.0867, 0.0214, 0.0346, 0.0173, 0.1101, -0.3066, 0.1115, 
    0.0415, 0.285, 0.0787, -0.0985, -0.027, -0.2767, 0.1572, 
    -0.0518, 0.0815, 0.0168, -0.2047, -0.1517, -0.0076, -0.0359, 
    0.0596, -0.0706, 0.1006, 0.0099, 0.1661, -0.0435, 0.0331, 
    0.0996, 0.197, -0.0067, -0.0328), torasemide = c(0.0987, 
    0.1829, 0.1693, -0.0482, 0.0534, 0.1624, 0.0047, -0.1721, 
    0.248, 0.1715, -0.2109, -0.0909, 0.0513, -0.1358, 0.6297, 
    0.0762, -0.3473, -0.2189, -0.126, 0.3054, -0.0451, -0.2243, 
    0.0914, -0.0199, -6e-04, -0.1102, -0.0082, 0.0242, -0.053, 
    -0.0825, -0.1874, 0.1251, 0, -0.0457, -0.1179, -0.3169, 0.0559, 
    0.1999, 0.262, 0.0462, 0.1038, -0.0999, -0.1278, -0.1944, 
    0.0074, 0.1785, 0.0486, -0.027, -0.2748, -0.0428, 0.0696, 
    -0.1544, 0.117, 0.1665, 0), troglitazone = c(-0.1513, 0.2568, 
    0.1377, 0.2474, -0.0359, -0.0859, 0.2014, 0.096, 0.0751, 
    0.1304, -0.1376, -0.1718, 0.0063, 0.2732, -0.2237, 0.1951, 
    -0.0496, -0.0087, 0.0245, -0.1212, 0.194, -0.0971, -0.0184, 
    0.1071, 0.0129, -0.061, 0.1704, -0.0021, 0.3985, 0.0963, 
    0.1591, -0.381, 0.2277, 0.5395, 0.0611, -0.0204, 0.0614, 
    -0.2816, 0.0308, -0.0642, -0.1722, -0.0191, -0.0374, 0.0436, 
    -0.3296, 0.0379, -0.0517, 0.2978, 0.0834, -0.1304, 0.1039, 
    0.2279, 0.5988, 0.0424, -0.2677), mepenzolate.bromide = c(0.0392, 
    -0.0041, -0.0531, -0.1213, -0.0919, 0.3096, 0.0545, 0.0922, 
    0.112, 0.0606, -0.25, -0.0086, 0.2729, 0.1307, 0.2124, -0.039, 
    -0.1005, 0.0125, 0.0644, -0.0064, 0.0707, 0.1931, -0.5523, 
    -0.285, -0.3085, 0.0343, 0.0622, -0.1849, -0.0436, 0.1069, 
    0.072, 0.0312, 0.1016, -0.1611, -0.139, 0.0047, 0.0297, -0.1409, 
    -0.0834, -0.0087, 0.2839, -0.03, -0.0378, -0.0705, 0.0836, 
    -0.0824, 0.0803, -0.1378, 0.014, -0.0351, 0.0049, 0.0153, 
    -0.093, 0.0263, 0.0855), megestrol = c(-0.1106, 0.2547, -0.0488, 
    0, -0.0406, -0.0826, -0.1795, -0.3099, -0.0316, 0.1563, 0, 
    -0.1189, -0.0343, -0.0482, 0.8041, 0.5202, 0.0733, 0.0419, 
    0.2212, -0.0888, 0.0268, 0.0886, -0.0476, -0.3235, -0.1348, 
    -0.2665, 0.294, 0.122, -0.1695, 0.1186, 0.0927, 0, -0.0429, 
    -0.0492, 0.0963, -0.0934, 0.1289, 0.1447, -0.0308, -0.1145, 
    0.1861, -0.0464, 0.0992, 0, 0.0771, -0.1804, 0.0899, 0.1031, 
    0, 0.1035, 0.1404, 0, -0.1281, -0.2463, -0.2874), dexpropranolol = c(-0.1942, 
    -0.0051, 0.0561, 0.0166, 0.0029, -0.1707, 0.2173, 0.1178, 
    -0.0683, -0.2903, -0.2874, 0.1764, -0.1135, 0.2574, 0, -0.1194, 
    -0.4694, -0.285, 0.0364, -0.0362, 0.158, -0.0648, -0.0046, 
    0.1435, -0.0946, 0.11, 0.1712, 0.3853, 0.1692, -0.0977, 0.3577, 
    0.2089, 0.3066, -0.0788, 0.3092, 0.113, -0.1234, 0.5753, 
    0.0359, 0.1014, 0.2017, 0.2949, 0.019, -0.0855, 0.0428, 0.2171, 
    -0.0951, -0.0761, -0.1451, -0.2832, -0.2653, -0.166, 0.0376, 
    -0.0214, 0.0131), nipecotic.acid = c(0.2653, -0.3115, -0.0069, 
    0.118, -0.0998, -0.0289, 0.1051, 0.0132, -0.0028, -0.1072, 
    -0.1888, -0.0312, 0.3868, -0.0019, -0.1878, -0.0798, -0.3881, 
    -0.2162, -0.1189, 0.1569, -0.0537, 0.0196, -0.0013, -0.0818, 
    -0.1885, 0.2266, 0.2862, 0.1302, 0.0734, 0.0936, -0.0159, 
    -0.0974, -0.0253, 0.2637, -0.2069, 0.2298, -0.1518, -0.13, 
    -0.0344, -0.0623, -0.0307, 0.1186, -0.2535, 0.0387, 0.0374, 
    0.0443, -0.0783, 0.1588, -0.0239, 0.1104, 0.1518, 0.1921, 
    -0.0744, -0.0125, -0.19), omeprazole = c(0.0272, -0.3796, 
    -0.0125, 0.0585, -0.1073, -0.0761, 0.3838, 0.5699, 0.0027, 
    -0.3822, 0.1132, -0.1588, 0.2396, -0.217, 0.0434, 0.1336, 
    -0.0608, -0.0294, 0.1702, -0.2499, 0.0568, 0.0348, -0.0486, 
    0, 0.2792, -0.1318, 0.0249, 0.005, 0.1688, -0.3908, -0.2366, 
    -0.0204, -0.0672, -0.0181, -0.0514, 0.139, 0.0582, 0.109, 
    0.1018, -0.2249, 0.0432, -0.1882, 0.0818, -0.1082, -0.0456, 
    -0.0764, 0.4292, 0.0553, -0.1346, -0.2173, 0, 0.1391, 0.1908, 
    -0.0633, 0.0385), etanidazole = c(-0.1036, 0.0281, 0.0039, 
    0.0123, -0.2305, -0.0542, 0.0485, -0.0686, -0.1829, 0.2637, 
    -0.1158, -0.2029, 0.104, 0.3169, 0.1387, 0.0844, -0.1385, 
    -0.3046, 0.0706, -0.076, -0.1772, 0, -0.393, 0.0841, -0.2469, 
    -0.1261, 0.1085, 0.0265, 0.0141, 0.0183, 0.2398, -0.0353, 
    -0.5217, -0.1577, 0.4357, -0.1347, 0.0362, 0.4197, -0.0326, 
    0.1955, -0.0352, -0.0122, -0.0658, -0.1482, -0.1485, 0.3406, 
    0.0618, 0.0822, 0.2024, -0.3203, 0.1646, -0.1412, 0.3221, 
    -8e-04, 0.0472), acenocoumarol = c(-0.0087, 0.2005, -0.1051, 
    -0.067, -0.0655, -0.0467, -0.4081, -0.1085, -0.0556, 0.0145, 
    -0.0865, 0.1961, -0.1842, -0.0398, -0.0944, 0.046, 0.0632, 
    -0.1008, 0.0837, 0.0023, 0.0482, 0.0195, -0.2322, -0.0293, 
    0.0671, -8e-04, -0.013, -0.0905, -0.0019, -0.0333, 0.0421, 
    -0.0712, -0.0771, 0.1843, 0.0589, 0.0229, -0.0976, -0.0184, 
    0.1559, -0.0297, -0.1089, -0.0461, -0.0322, 0.1253, 0.0408, 
    -0.1147, 0.082, 0.1072, 0.1094, 0.1066, 0.104, 0.1947, 0.1116, 
    -0.1421, -0.0934), dacarbazine = c(-0.0065, -0.7082, 0.0979, 
    0.0048, -0.1409, 0.0541, -0.0793, -0.1102, -0.1513, -0.002, 
    -0.0898, 0.0443, 0.0686, -0.1122, -0.0239, 0.0126, -0.0093, 
    0.0366, 0.0061, -0.1217, 0.0259, -0.1117, -0.1178, -0.2467, 
    -0.1128, -0.0671, 0.0347, 0.4719, -0.3849, -0.0517, 0.0764, 
    0.2058, 0.3147, 0.3275, 0.551, 0.1175, 0.0383, -0.1004, 0.0425, 
    0.1717, 0.174, 0.0122, -0.1466, 0.0381, -0.0656, 0.2572, 
    -0.0851, 0.0996, -0.2686, -0.1501, 0.0994, 0.001, 0.0891, 
    0.0652, -0.2386), diphemanil.metilsulfate = c(-0.0312, -0.2611, 
    -0.0098, -0.216, 0.24, 0.0909, 0.1171, -0.156, 0.0986, -0.0946, 
    0.1027, -0.1465, 0.0611, 0.0637, 0.0677, -0.0017, -0.0884, 
    -0.0023, 0.012, -0.3062, -0.0396, -0.0197, -0.2654, -0.1362, 
    -0.1075, 0.0738, 0.0039, -0.047, -0.0562, -0.0751, 0.0048, 
    -0.0273, 0.1636, -0.003, 0.1565, 0.2033, -0.1181, -0.046, 
    0.0056, 0.0896, -0.0309, -0.0146, -0.0784, 0.002, 0.1111, 
    0.2156, 0.0915, 0.1174, 0.2337, -0.0151, -0.056, 0.0705, 
    0.0522, -0.0171, -0.3229), meprylcaine = c(-0.0382, -0.1127, 
    0, 0, 0.0964, 0.0097, -0.0231, -0.0747, 0.2147, 0.0618, -0.2313, 
    0.0878, -0.3681, 0.0497, -0.0105, 0.2084, 0.0492, 0.0423, 
    0.0634, -0.0457, -0.0883, 0.0104, 0.1429, -0.1485, 0.4838, 
    0.0139, 0.2511, -0.1276, -0.1517, -0.0574, -0.0525, -0.0053, 
    -0.0796, 0.1029, -0.0393, -0.0587, -0.1787, -0.2193, 0.1723, 
    0.1684, 0.1708, 0.1961, -0.027, 0.0921, -0.0293, -0.2186, 
    -0.1013, -0.043, 0.2408, -0.2149, 0.2316, -0.0559, 0.2917, 
    -0.0128, -0.2173), mevalolactone = c(-0.0393, -0.174, -0.1632, 
    0.4181, -0.038, 0.1698, -0.1771, -0.168, -0.3952, 0.1739, 
    0.1304, 0, -0.0317, -0.1822, -0.2021, -0.0743, 0.3155, 0.0782, 
    0.2533, -0.1159, 0.0135, 0.2274, -0.1785, -0.4384, -0.268, 
    0.1331, -0.4809, 0.6483, -0.7939, -0.1549, -0.0138, -0.0604, 
    0.043, 0.1208, 0.4608, 0.4028, 0.1985, 0.1172, 0.0787, 0.099, 
    -0.0329, 0.1553, -0.0503, -0.1355, 0.0382, 0.4655, -0.1948, 
    -0.1411, -0.0149, 0.0259, -0.4708, 0.0715, 0.0608, 0, 0.5629
    ), buspirone = c(-0.1276, -0.0097, -0.1365, 0.0801, -0.0499, 
    0.0499, 0.2245, 0.0739, -0.0485, -0.0042, -0.2356, -0.1325, 
    0, 0, -0.0756, 0.0099, 0.069, 0.062, 0.0404, 0.2093, -0.0973, 
    -0.237, -0.2371, 0.1403, -0.0553, -0.043, 0.0219, 0.0596, 
    0.0999, -0.1358, 0.1098, -0.06, 0.1429, -0.0758, 0.1528, 
    -0.0426, 0.1053, 0.2444, -0.0031, -0.2131, -0.1855, 0.144, 
    0.0037, 0.1078, 0.2742, 0.247, 0.0755, 0.0187, 0.0075, -0.0934, 
    -0.2814, 0.1086, -0.379, -0.1291, -0.0597), sulfafurazole = c(0.0336, 
    0.0083, 0.0309, 0.1891, -0.0991, 0.0259, 0.084, 0.0888, 0.0672, 
    -0.0859, -0.0196, -0.4085, 0.0676, 0.0357, -0.0486, -0.2493, 
    -0.053, -0.128, 0.103, -0.0471, 0.0839, 0.3382, 0.1353, 0.2906, 
    0.1022, -0.1326, -0.0457, 0.3148, 0.2374, 0.0719, 0.0469, 
    -0.2298, 0.1334, 0.1581, -0.1396, -0.2614, -2e-04, 0.0297, 
    -0.0349, -0.1307, -0.1516, -0.0526, 0.0468, 0.0534, -0.0268, 
    0.2099, -0.0794, 0.2252, 0.095, -0.1607, 0.1593, 0.0157, 
    0.0283, 0.1304, -8e-04), ciclopirox = c(0.0958, 0.2534, -0.1897, 
    -0.0457, 0.1704, -0.2632, -0.2596, -0.1076, 0.3008, 0.1348, 
    -0.0817, 0.2929, -0.2249, -0.1357, -0.0498, 0.3122, 0.1269, 
    0.0809, 0.05, -0.2514, -0.3665, -0.1104, 0.0793, 0.8682, 
    0.3056, 0.2149, -0.3415, 0.1955, 0.2518, -0.1525, 0.0429, 
    0.4573, -0.556, -0.2508, 0.0437, 0.0459, 0.13, 0.104, 8e-04, 
    -0.5053, -0.4061, -0.2273, 0.1871, 0.1646, -0.0224, 0.1323, 
    -0.1473, -0.0917, -0.214, 0.0844, -0.4498, 0.0313, 0.0385, 
    -0.1485, -0.0553)), .Names = c("phenelzine", "denatonium.benzoate", 
"triamterene", "talampicillin", "triamcinolone", "sulfaphenazole", 
"procyclidine", "pentoxifylline", "suloctidil", "etacrynic.acid", 
"diphenylpyraline", "carbenoxolone", "arecoline", "chenodeoxycholic.acid", 
"torasemide", "troglitazone", "mepenzolate.bromide", "megestrol", 
"dexpropranolol", "nipecotic.acid", "omeprazole", "etanidazole", 
"acenocoumarol", "dacarbazine", "diphemanil.metilsulfate", "meprylcaine", 
"mevalolactone", "buspirone", "sulfafurazole", "ciclopirox"), row.names = c("200665_s_at", 
"201125_s_at", "201150_s_at", "201162_at", "201560_at", "202133_at", 
"202435_s_at", "202436_s_at", "202766_s_at", "203083_at", "203238_s_at", 
"203640_at", "204223_at", "204468_s_at", "204589_at", "204619_s_at", 
"205381_at", "205422_s_at", "205713_s_at", "205941_s_at", "208626_s_at", 
"209581_at", "209747_at", "209875_s_at", "209894_at", "210004_at", 
"210078_s_at", "210495_x_at", "210511_s_at", "210517_s_at", "210809_s_at", 
"211071_s_at", "211597_s_at", "211709_s_at", "211719_x_at", "212464_s_at", 
"212488_at", "212667_at", "213125_at", "213351_s_at", "213352_at", 
"213413_at", "213656_s_at", "214770_at", "214927_at", "216442_x_at", 
"217428_s_at", "217949_s_at", "218718_at", "219054_at", "219087_at", 
"219179_at", "219922_s_at", "222379_at", "37022_at"), class = "data.frame")

我想基于那些平均值高于0.02的行来热映射所有列。

我所做的如下:

tab <- melt(transform(df, rowname = row.names(df)))
t<- data.frame(sort(rowMeans(df)))
t[t[,1] > 0.02,, drop=FALSE]

library(ggplot2)

ggplot(subset(tab, rowname %in% rownames(t)[t > 0.02]), 
           aes(x = rowname, y = variable, fill = value)) + 
      geom_tile() + 
      scale_fill_gradient2(high="red",mid="white",low="blue") +
      theme(axis.text.x = element_text(angle = 90, vjust = 0.5)) 

但它没有完成这项工作,它确实根据订单放置了x轴,例如我希望从0.02到0.05 所以另一个看起来像

204619_s_at         0.02055667
211709_s_at         0.02357333
216442_x_at         0.02364000
201162_at           0.02389667
217949_s_at         0.03153333
201150_s_at         0.03251000
204468_s_at         0.03279000
211719_x_at         0.03447667
219922_s_at         0.03968667
212667_at           0.04798667
212488_at           0.04833333
209875_s_at         0.05173333
203083_at           0.05493667
210495_x_at         0.05858333
219179_at           0.05932667

在轴而不是它显示的内容

1 个答案:

答案 0 :(得分:1)

你可以尝试

rn <- rownames(t[t[,1] > 0.02,, drop=FALSE])
tab1 <-  subset(tab, rowname %in% rownames(t)[t > 0.02])
tab1$rowname <- factor(tab1$rowname, levels=rn)

library(ggplot2)

 ggplot(tab1,aes(x = rowname, y = variable, fill = value)) + 
         geom_tile() + 
         scale_fill_gradient2(high="red",mid="white",low="blue") +
         theme(axis.text.x = element_text(angle = 90, vjust = 0.5)) 

或保留%>%

中的大多数步骤
 library(dplyr)
 library(tidyr)
 library(ggplot2)

 bind_cols(data.frame(rowname=row.names(df)), df) %>%
    filter(rowMeans(.[-1]) >0.02) %>% 
    gather(variable, value,-rowname) %>%
    mutate(rowname=factor(rowname, levels=rn)) %>%
    ggplot(., aes(x=rowname, y=variable, fill=value))+ 
       geom_tile()+
       scale_fill_gradient2(high='red', mid='white', low='blue')+
       theme(axis.text.x = element_text(angle = 90, vjust=0.5)) +
       xlab('x axis') +
       ylab('y axis')

enter image description here