ggplot2中的2d轮廓颜色图

时间:2018-05-02 09:09:24

标签: r ggplot2

我有大量数据,请耐心等待。

df <- structure(list(W = c(5216400.4123, 5399804.7349, 5595563.3087, 
5792353.9932, 5993467.7466, 6189404.9279, 6380940.454, 6566630.3544, 
6747453.6816, 6917820.9796, 7086201.8275, 7248213.5225, 5402700.4252, 
5592654.9057, 5795404.8549, 5999223.7818, 6207520.1695, 6410455.1037, 
6608831.1825, 6801152.8706, 6988434.1695, 7164886.0132, 7339280.46, 
7507078.2886, 5589000.4397, 5785505.0748, 5995246.3993, 6206093.5662, 
6421572.589, 6631505.2817, 6836721.9131, 7035675.3828, 7229414.6578, 
7411951.0459, 7592359.0997, 7765943.0584, 5775300.4552, 5978355.2455, 
6195087.9484, 6412963.3504, 6635625.0103, 6852555.4544, 7064612.6447, 
7270197.897, 7470395.1463, 7659016.0859, 7845437.7356, 8024807.8293, 
5961600.4694, 6171205.4145, 6394929.4952, 6619833.1358, 6849677.4283, 
7073605.633, 7292503.372, 7504720.4062, 7711375.6354, 7906081.1161, 
8098516.3724, 8283672.5987, 6147900.4816, 6364055.583, 6594771.0412, 
6826702.9212, 7063729.8478, 7294655.8114, 7520394.1023, 7739242.9195, 
7952356.1253, 8153146.1541, 8351595.0092, 8542537.3639, 6334200.5005, 
6556905.7553, 6794612.5881, 7033572.7089, 7277782.2661, 7515705.9882, 
7748284.8337, 7973765.4322, 8193336.6123, 8400211.1873, 8604673.6477, 
8801402.1321, 6520500.5136, 6749755.9226, 6994454.1327, 7240442.494, 
7491834.6868, 7736756.1617, 7976175.5621, 8208287.9459, 8434317.1037, 
8647276.2228, 8857752.2827, 9060266.9029, 6706800.528, 6942606.0899, 
7194295.6809, 7447312.2777, 7705887.1079, 7957806.3409, 8204066.2961, 
8442810.4584, 8675297.5886, 8894341.2573, 9110830.9206, 9319131.6718, 
6893100.5418, 7135456.2602, 7394137.2288, 7654182.0653, 7919939.5232, 
8178856.5136, 8431957.0234, 8677332.969, 8916278.0804, 9141406.2918, 
9363909.5543, 9577996.4404, 7079400.5588, 7328306.4296, 7593978.7729, 
7861051.8503, 8133991.9462, 8399906.6912, 8659847.7579, 8911855.4821, 
9157258.5684, 9388471.3277, 9616988.1903, 9836861.209, 7265700.5699, 
7521156.5994, 7793820.3185, 8067921.639, 8348044.3652, 8620956.868, 
8887738.4844, 9146377.9962, 9398239.0552, 9635536.362, 9870066.8286, 
10095725.9764, 7377480.5806, 7636866.7018, 7913725.2471, 8192043.5082, 
8476475.8166, 8753586.9712, 9024472.9255, 9287091.5011, 9542827.3494, 
9783775.3823, 10021914.0099, 10251044.8357, 7452000.5846, 7714006.7682, 
7993661.8669, 8274791.4235, 8562096.7846, 8842007.041, 9115629.2162, 
9380900.5049, 9639219.5459, 9882601.398, 10123145.4642, 10354590.7474, 
7526520.5952, 7791146.8356, 8073598.4841, 8357539.3348, 8647717.7534, 
8930427.113, 9206785.5068, 9474709.5143, 9735611.7438, 9981427.4094, 
10224376.9194, 10458136.6527, 7638300.6025, 7906856.9365, 8193503.4143, 
8481661.2074, 8776149.2063, 9063057.2172, 9343519.9463, 9615423.0209, 
9880200.0383, 10129666.4312, 10376224.1032, 10613455.5131, 7824600.6172, 
8099707.1074, 8393344.9601, 8688530.993, 8990201.627, 9284107.395, 
9571410.6772, 9849945.5329, 10121180.5245, 10376731.4677, 10629302.7393, 
10872320.2844, 8010900.6306, 8292557.2766, 8593186.5077, 8895400.7788, 
9204254.0428, 9505157.5709, 9799301.4089, 10084468.0455, 10362161.0109, 
10623796.504, 10882381.3729, 11131185.0534, 8197200.6444, 8485407.4453, 
8793028.0567, 9102270.5614, 9418306.465, 9726207.7477, 10027192.1371, 
10318990.5604, 10603141.4991, 10870861.5368, 11135460.012, 11390049.8203, 
8383500.6593, 8678257.6128, 8992869.6005, 9309140.3471, 9632358.8856, 
9947257.9225, 10255082.8657, 10553513.0731, 10844121.988, 11117926.5692, 
11388538.6484, 11648914.5899, 8569800.6735, 8871107.7799, 9192711.1487, 
9516010.1349, 9846411.3046, 10168308.0987, 10482973.5998, 10788035.5824, 
11085102.4738, 11364991.6051, 11641617.2821, 11907779.3576, 8756100.6891, 
9063957.9534, 9392552.6936, 9722879.9204, 10060463.7195, 10389358.2746, 
10710864.3279, 11022558.0956, 11326082.9668, 11612056.6477, 11894695.9209, 
12166644.1258, 8942400.705, 9256808.1204, 9592394.2396, 9929749.7037, 
10274516.1413, 10610408.4494, 10938755.0613, 11257080.6099, 11567063.455, 
11859121.6771, 12147774.5594, 12425508.8956, 9128700.7203, 9449658.2901, 
9792235.786, 10136619.4908, 10488568.5635, 10831458.6249, 11166645.792, 
11491603.1215, 11808043.9427, 12106186.7106, 12400853.1962, 12684373.664, 
9315000.7353, 9642508.4595, 9992077.3349, 10343489.2758, 10702620.9802, 
11052508.7998, 11394536.5185, 11726125.6341, 12049024.431, 12353251.7462, 
12653931.8307, 12943238.4324, 9501300.7465, 9835358.6307, 10191918.8807, 
10550359.0623, 10916673.4022, 11273558.9758, 11622427.2509, 11960648.1479, 
12290004.92, 12600316.7835, 12907010.4688, 13202103.2002, 9687600.7612, 
10028208.7979, 10391760.4269, 10757228.8467, 11130725.8198, 11494609.1532, 
11850317.9787, 12195170.6632, 12530985.4111, 12847381.8161, 13160089.1051, 
13460967.9711), t = structure(c(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 
12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 
6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 
12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 
6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 
12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 
6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 
12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 
6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 
12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 
6L, 7L, 8L, 9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 
9L, 10L, 11L, 12L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 
12L), .Label = c("t_m75_tc", "t_m5_tc", "t_m25_tc", "t_p0_tc", 
"t_p25_tc", "t_p5_tc", "t_p75_tc", "t_p10_tc", "t_p125_tc", "t_p15_tc", 
"t_p175_tc", "t_p20_tc"), class = "factor"), p = structure(c(1L, 
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 
2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 
5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 5L, 6L, 6L, 6L, 6L, 6L, 
6L, 6L, 6L, 6L, 6L, 6L, 6L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 7L, 
7L, 7L, 7L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 8L, 9L, 
9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 9L, 10L, 10L, 10L, 10L, 
10L, 10L, 10L, 10L, 10L, 10L, 10L, 10L, 11L, 11L, 11L, 11L, 11L, 
11L, 11L, 11L, 11L, 11L, 11L, 11L, 12L, 12L, 12L, 12L, 12L, 12L, 
12L, 12L, 12L, 12L, 12L, 12L, 13L, 13L, 13L, 13L, 13L, 13L, 13L, 
13L, 13L, 13L, 13L, 13L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 14L, 
14L, 14L, 14L, 14L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 15L, 
15L, 15L, 15L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 
16L, 16L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 17L, 
17L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 18L, 
19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 19L, 20L, 
20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 20L, 21L, 21L, 
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 22L, 22L, 22L, 
22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 22L, 23L, 23L, 23L, 23L, 
23L, 23L, 23L, 23L, 23L, 23L, 23L, 23L, 24L, 24L, 24L, 24L, 24L, 
24L, 24L, 24L, 24L, 24L, 24L, 24L, 25L, 25L, 25L, 25L, 25L, 25L, 
25L, 25L, 25L, 25L, 25L, 25L, 26L, 26L, 26L, 26L, 26L, 26L, 26L, 
26L, 26L, 26L, 26L, 26L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 27L, 
27L, 27L, 27L, 27L), .Label = c("h_30", "h_27.5", "h_25", "h_22.5", 
"h_20", "h_17.5", "h_15", "h_12.5", "h_10", "h_7.5", "h_5", "h_2.5", 
"h_1", "h0", "h1", "h2.5", "h5", "h7.5", "h10", "h12.5", "h15", 
"h17.5", "h20", "h22.5", "h25", "h27.5", "h30"), class = "factor"), 
    tt = c(-7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10, 12.5, 15, 17.5, 
    20, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10, 12.5, 15, 17.5, 20, 
    -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10, 12.5, 15, 17.5, 20, -7.5, 
    -5, -2.5, 0, 2.5, 5, 7.5, 10, 12.5, 15, 17.5, 20, -7.5, -5, 
    -2.5, 0, 2.5, 5, 7.5, 10, 12.5, 15, 17.5, 20, -7.5, -5, -2.5, 
    0, 2.5, 5, 7.5, 10, 12.5, 15, 17.5, 20, -7.5, -5, -2.5, 0, 
    2.5, 5, 7.5, 10, 12.5, 15, 17.5, 20, -7.5, -5, -2.5, 0, 2.5, 
    5, 7.5, 10, 12.5, 15, 17.5, 20, -7.5, -5, -2.5, 0, 2.5, 5, 
    7.5, 10, 12.5, 15, 17.5, 20, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 
    10, 12.5, 15, 17.5, 20, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10, 
    12.5, 15, 17.5, 20, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10, 12.5, 
    15, 17.5, 20, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10, 12.5, 15, 
    17.5, 20, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10, 12.5, 15, 17.5, 
    20, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10, 12.5, 15, 17.5, 20, 
    -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10, 12.5, 15, 17.5, 20, -7.5, 
    -5, -2.5, 0, 2.5, 5, 7.5, 10, 12.5, 15, 17.5, 20, -7.5, -5, 
    -2.5, 0, 2.5, 5, 7.5, 10, 12.5, 15, 17.5, 20, -7.5, -5, -2.5, 
    0, 2.5, 5, 7.5, 10, 12.5, 15, 17.5, 20, -7.5, -5, -2.5, 0, 
    2.5, 5, 7.5, 10, 12.5, 15, 17.5, 20, -7.5, -5, -2.5, 0, 2.5, 
    5, 7.5, 10, 12.5, 15, 17.5, 20, -7.5, -5, -2.5, 0, 2.5, 5, 
    7.5, 10, 12.5, 15, 17.5, 20, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 
    10, 12.5, 15, 17.5, 20, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10, 
    12.5, 15, 17.5, 20, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10, 12.5, 
    15, 17.5, 20, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10, 12.5, 15, 
    17.5, 20, -7.5, -5, -2.5, 0, 2.5, 5, 7.5, 10, 12.5, 15, 17.5, 
    20), hh = c(-30, -30, -30, -30, -30, -30, -30, -30, -30, 
    -30, -30, -30, -27.5, -27.5, -27.5, -27.5, -27.5, -27.5, 
    -27.5, -27.5, -27.5, -27.5, -27.5, -27.5, -25, -25, -25, 
    -25, -25, -25, -25, -25, -25, -25, -25, -25, -22.5, -22.5, 
    -22.5, -22.5, -22.5, -22.5, -22.5, -22.5, -22.5, -22.5, -22.5, 
    -22.5, -20, -20, -20, -20, -20, -20, -20, -20, -20, -20, 
    -20, -20, -17.5, -17.5, -17.5, -17.5, -17.5, -17.5, -17.5, 
    -17.5, -17.5, -17.5, -17.5, -17.5, -15, -15, -15, -15, -15, 
    -15, -15, -15, -15, -15, -15, -15, -12.5, -12.5, -12.5, -12.5, 
    -12.5, -12.5, -12.5, -12.5, -12.5, -12.5, -12.5, -12.5, -10, 
    -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -10, -7.5, 
    -7.5, -7.5, -7.5, -7.5, -7.5, -7.5, -7.5, -7.5, -7.5, -7.5, 
    -7.5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -5, -2.5, 
    -2.5, -2.5, -2.5, -2.5, -2.5, -2.5, -2.5, -2.5, -2.5, -2.5, 
    -2.5, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 
    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 
    1, 1, 1, 1, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 2.5, 
    2.5, 2.5, 2.5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 7.5, 7.5, 
    7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 7.5, 10, 10, 
    10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 12.5, 12.5, 12.5, 
    12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 12.5, 15, 
    15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 17.5, 17.5, 17.5, 
    17.5, 17.5, 17.5, 17.5, 17.5, 17.5, 17.5, 17.5, 17.5, 20, 
    20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 22.5, 22.5, 22.5, 
    22.5, 22.5, 22.5, 22.5, 22.5, 22.5, 22.5, 22.5, 22.5, 25, 
    25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 27.5, 27.5, 27.5, 
    27.5, 27.5, 27.5, 27.5, 27.5, 27.5, 27.5, 27.5, 27.5, 30, 
    30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30), pChange = c(-36.9603395985828, 
    -34.7439172960321, -32.3781951432773, -30.0000000392759, 
    -27.5695610939649, -25.2016804880133, -22.8869934306931, 
    -20.6429501564101, -18.4577189167867, -16.3988477104845, 
    -14.3639825485445, -12.4060879418008, -34.7089231777299, 
    -32.4133428932464, -29.9631306906258, -27.5000000028702, 
    -24.982759663634, -22.5303119363876, -20.1329575059591, -17.8087697620382, 
    -15.5454946011909, -13.4130922883195, -11.3055534045631, 
    -9.27773397066822, -32.4575067375413, -30.082768511005, -27.5480662597272, 
    -25.000000017221, -22.3959582743917, -19.8589433581751, -17.3789215558468, 
    -14.974589416006, -12.6332702807612, -10.4273368770308, -8.24712417357041, 
    -6.14937995482153, -30.2060902852677, -27.7521941094277, 
    -25.1330017720295, -22.5000000339888, -19.8091568633966, 
    -17.1875748440126, -14.6248855936495, -12.1404090458039, 
    -9.72104595791446, -7.44158137752243, -5.18869498850033, 
    -3.02102592568144, -27.9546738487045, -25.4216197283948, 
    -22.7179373121271, -20.0000000362547, -17.2223554922816, 
    -14.5162062585492, -11.8708496834174, -9.30622873602633, 
    -6.80882162781682, -4.45582599644603, -2.13026579255384, 
    0.107328085331291, -25.7032574363111, -23.0910453534044, 
    -20.3028728618926, -17.5000000385206, -14.6355541030393, 
    -11.8448376755028, -9.11681373693055, -6.47204837670069, 
    -3.89659728805126, -1.47007052110743, 0.928163403392649, 
    3.23568204558746, -23.4518409429489, -20.7604709324913, -17.8878084007817, 
    -15.0000000129913, -12.0487527282989, -9.17346911179217, 
    -6.36277777715033, -3.63786802462598, -0.984372983331903, 
    1.51568489622367, 3.98659261988347, 6.36403604209831, -21.2004245196791, 
    -18.4298965720027, -15.4727439674661, -12.5000000188826, 
    -9.46195132455473, -6.50210058796172, -3.6087418536248, -0.803687660466381, 
    1.92785137456101, 4.50144034135001, 7.04502179407714, 9.4923900700299, 
    -18.949008080699, -16.0993222115141, -13.0576794906449, -10.0000000416929, 
    -6.8751499159766, -3.83073199524737, -0.85470586242384, 2.03049268919135, 
    4.84007565390208, 7.48719577439149, 10.103451003317, 12.6207440750002, 
    -16.6975916489697, -13.7687478147708, -10.6426150174491, 
    -7.50000001737204, -4.28834857749088, -1.15936348108484, 
    1.8993300478083, 4.86467301588778, 7.75230001662893, 10.4729512074329, 
    13.1618801618003, 15.749098076345, -14.4461751785688, -11.4381734289039, 
    -8.2275505901759, -5.00000002447191, -1.70154714595145, 1.51200509229367, 
    4.65336604505171, 7.69885337279645, 10.6645243334332, 13.4587066573933, 
    16.2203093480789, 18.8774520776898, -12.1947587794688, -9.10759903820312, 
    -5.81248614477539, -2.49999998685766, 0.885254237248392, 
    4.18337365600429, 7.40740194561595, 10.53303374179, 13.5767486357356, 
    16.4444620880177, 19.2787385621527, 22.0058060645328, -10.8439088911858, 
    -7.70925439749847, -4.3634474625498, -1.00000001287041, 2.43733506716831, 
    5.78619475942614, 9.05982354879595, 12.2335419201639, 15.324083242737, 
    18.2359153430087, 21.1137960702944, 23.8828184428618, -9.94334233686319, 
    -6.77702465958718, -3.39742166553716, 0, 3.47205562528221, 
    6.85474217379226, 10.1614379102301, 13.3672140455251, 16.4889729851691, 
    19.4302175391865, 22.3371677435973, 25.1341600948813, -9.04277570278022, 
    -5.84479490959099, -2.43139589994524, 0.999999964530837, 
    4.50677619306401, 7.92328961474518, 11.2630522704558, 14.5008862385618, 
    17.65386274452, 20.6245196833994, 23.5605394277767, 26.3855016695576, 
    -7.69192585558588, -4.44645028701369, -0.982357198383821, 
    2.49999997960674, 6.05885704111126, 9.52611073025193, 12.9154738543, 
    16.20139443748, 19.4011973551469, 22.4159729565176, 25.3955969661306, 
    28.26251406118, -5.44050941298024, -2.11587588301946, 1.43270724943368, 
    4.99999997975781, 8.64565844485543, 12.1974793060474, 15.6695098080378, 
    19.0355747810953, 22.3134216501983, 25.4017284137289, 28.4540261536177, 
    31.390868095154, -3.18909298608498, 0.214698500430437, 3.84777171900399, 
    7.49999998232584, 11.2324597893836, 14.8688478588816, 18.4235457714435, 
    21.8697551319615, 25.2256459476667, 28.3874838685232, 31.5124553108925, 
    34.5192221013328, -0.93767655435575, 2.54527287783788, 6.26283620549316, 
    9.99999994622222, 13.8192612112551, 17.5402164225922, 21.177581692552, 
    24.703935510623, 28.1378702668879, 31.3732392810203, 34.5708845346342, 
    37.6475760821333, 1.31373989066688, 4.87584724074345, 8.67790062914087, 
    12.4999999475818, 16.4060626137908, 20.211584962133, 23.9316176184945, 
    27.5381158626977, 31.0500945945686, 34.3589946886835, 37.6293137257467, 
    40.775930095563, 3.56515632723005, 7.20642159881506, 11.0929651059621, 
    14.9999999743196, 18.9928639969906, 22.8829535185927, 26.685653610904, 
    30.3722961736837, 33.9623188847861, 37.3447501386438, 40.6877428842301, 
    43.9042840860314, 5.81657278071209, 9.53699603423, 13.5080295429032, 
    17.4999999732622, 21.5796653306424, 25.5543220714269, 29.439689530804, 
    33.2064765318009, 36.8745432620148, 40.3305056695729, 43.7461721043463, 
    47.0326380825422, 8.06798923781962, 11.8675703910931, 15.9230939931377, 
    19.999999945618, 24.16646674768, 28.2256906109677, 32.1937255147541, 
    36.0406569032114, 39.7867675812361, 43.3162610409814, 46.8046013208372, 
    50.1609920983889, 10.3194056876762, 14.1981447805855, 18.3381584482061, 
    22.4999999638964, 26.7532681695515, 30.8970591589679, 34.9477614660749, 
    38.8748372419928, 42.6989918944149, 46.302016461938, 49.8630305167836, 
    53.2893460973168, 12.5708221339073, 16.5287191664524, 20.7532229334868, 
    24.9999999567965, 29.3400695249561, 33.5684276997172, 37.7017973666391, 
    41.709017592859, 45.6112162148446, 49.2877719082728, 52.9214596849349, 
    56.4177000962446, 14.8222385342158, 18.859293574072, 23.1682873813043, 
    27.499999967824, 31.9268709444106, 36.2397962537599, 40.4558333385042, 
    44.5431979582271, 48.5234405437337, 52.273527375152, 55.9798888965917, 
    59.5460540879215, 17.0736549768214, 21.1898679333522, 25.5833518339557, 
    29.9999999534732, 34.5136723106916, 38.9111648247215, 43.2098692547788, 
    47.3773783417225, 51.4356648980012, 55.2592827852321, 59.0383180864958, 
    62.6744081170616)), class = "data.frame", .Names = c("W", 
"t", "p", "tt", "hh", "pChange"), row.names = c(NA, -324L))

我正在尝试绘制带有tt, hh and W列的彩色等高线图,W是z轴。

这是我正在使用的代码::

ggplot(df, aes(x = tt, y = hh, z = W)) +
  stat_contour(geom = "polygon", aes(fill = ..level..) ) +
  geom_tile(aes(fill = W)) +
  stat_contour(bins = 10) +
  xlab("% change in temperature") +
  ylab("% change in ppt") +
  guides(fill = guide_colorbar(title = "W"))

这是我得到的结果: enter image description here

我想要的是连续的颜色,如here我正在关注this example工作。

这里出了什么问题?

1 个答案:

答案 0 :(得分:1)

网格间距不均匀。制作均匀间隔网格的一种方法是在均匀间隔的网格上使用loess进行插值:

model <- loess(W ~ tt + hh, data = df) 

使用expand.grid:

创建均匀间隔的网格
new.data <- expand.grid(tt = seq(from = min(df$tt), to = max(df$tt), length.out = 500),
                        hh = seq(from = min(df$hh), to = max(df$hh), length.out = 500))

使用该模型预测新数据:

gg <- predict(model, newdata =  new.data)

结合预测和新数据:

new.data = data.frame(W = as.vector(gg),
                      new.data)

现在情节如下:

  ggplot(new.data, aes(x = tt, y = hh, z = W)) +
    stat_contour(geom = "polygon", aes(fill = ..level..) ) +
    geom_tile(aes(fill = W)) +
    stat_contour(bins = 10) +
    xlab("% change in temperature") +
    ylab("% change in ppt") +
    guides(fill = guide_colorbar(title = "W"))

enter image description here

您可能还想检查loess

的某些拟合优度指标
caret::RMSE(model$fitted, df$W)
#output
7498.393

使用较窄的跨度可以提供更好的拟合,尤其是在数据不平滑的情况下:

model2 <- loess(W ~ tt + hh, data = df, span = 0.1) 
caret::RMSE(model2$fitted, df$W)
#output
964.7582

ggplot(new.data2, aes(x = tt, y = hh, z = W)) +
  stat_contour(geom = "polygon", aes(fill = ..level..) ) +
  geom_tile(aes(fill = W)) +
  stat_contour(bins = 10) +
  xlab("% change in temperature") +
  ylab("% change in ppt") +
  guides(fill = guide_colorbar(title = "W"))

enter image description here

差异太小了

ggplot(new.data, aes(x = tt, y = hh, z = W)) +
  geom_tile(aes(fill = W)) +
  geom_contour(aes(x = tt, y = hh, z = W),
               color = "red")+ 
  geom_contour(data = new.data2,
               aes(x = tt, y = hh, z = W),
               color = "white", inherit.aes = FALSE) 

enter image description here

编辑:还要查看@Henrik的精彩帖子,评论中链接了他。特别是?akima::interp函数。

EDIT2:回答评论中的问题:

要指定不同的填充,可以使用

scale_fill_gradient
scale_fill_gradient2
scale_fill_gradientn

以下是基于scale_fill_gradientn使用quantiles 5种颜色的示例:

v <- ggplot(new.data2, aes(x = tt, y = hh, z = floor(W))) +
  geom_tile(aes(fill = W), show.legend = FALSE) +
  stat_contour(bins = 10, aes(colour = ..level..)) +
  xlab("% change in temperature") +
  ylab("% change in ppt") +
  guides(fill = guide_colorbar(title = "W")) +
  scale_fill_gradientn(values = scales::rescale(quantile(new.data2$W)),
                       colors = rainbow(5))

我删除了polygon内容,因为它位于geom_tile图层下方并且不可见。

添加直接标签:

library(directlabels)

direct.label(v, list("far.from.others.borders", "calc.boxes", "enlarge.box", 
                     box.color = NA, fill = "transparent", "draw.rects"))

enter image description here