我有一个数据集,我可以很好地绘制数据集,但是,我的图表上有三条线,我想在它们之间进行阴影(所以两个阴影区域)。
ZNH2<-structure(list(value = c("154.102123376241", "129.342971722961",
"59.214424508985", NA, "79.7543253228812", "56.9720749846859",
"147.904588068996", "127.832589574989", "41.9504584377476", "30.210899339716",
"189.915069536722", "206.470143151635", "269.431758501289", "330.519022331884",
"80.9548026764334", "135.275345151106", "70.8898624532545", "333.065088493364",
"245.671050594358", "217.694093154847", "202.293931253186", "320.08224840969",
"152.675949949667", "85.6197139863922", "71.1857213343614", "222.044301846973",
"111.437578615948", "991.558657706669", "77.5176101480006", "90.3789552959655",
"117.223606151342", "44.9530550879222", "167.092674420099", "175.107272805158",
"196.46944973477", "154.071757533894", "118.28502485382", "122.756078599527",
"79.8304508785081", "226.840582406991", "119.065146684801", "170.225407520687",
"177.651665865621", "175.597432999921", "104.179544790707", NA,
NA, NA, NA, NA, NA, NA, NA, "16.8437034171218", "21.589296969022",
"21.5293178756595", NA, "17.1577492347234", "15.9453880616562",
"45.8596992672078", "44.8514087972185", "24.0627701288669", "130.128455156461",
"72.9531584398895", "34.6680166210599", "68.0830269285413", "45.5857868971278",
"34.962220142646", "149.522794107249", "43.5106817194628", "80.1849936102008",
"50.1407523335261", "25.7103931548188", "51.707257838463", "56.514058394911",
"47.697772888689", "65.17156146864", "20.165819163686", "92.7341148329014",
"62.2774860245454", "187.079350368038", "41.5562639058451", "28.8978603742495",
"41.1724906723211", "5.77878944647918", "56.0880422383573", "68.4731748377562",
"74.0245489658521", "44.7719649917539", "15.1070354391827", NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "0",
"0", "0", NA, "0", NA, "0.061935327", NA, "0.238451009", "0.006193533",
"0", "0", "0.015483832", "0", NA, "0.390192559", "0.300386335",
"0.105290056", "0", NA, "0.015483832", "0", "0.191999513", "0.151741551",
"0.09290299", "0.021677364", "0", "0", "0.086709458", "0", "0",
"0", NA, NA, NA, "0.021677364", NA, "0", "0", NA, "0", "0", "0",
NA, "0.030750948", "0.00615019", "0", "0", "0", "0", "0", "0",
"0", "0.018450569", "0", "0", "0", "0", NA, "0.017852517", "0",
NA, NA, NA, "0", NA, "0", "0.014648219", NA, "0", "0.017852517",
"0.008239623", NA, "0.017852517", "0", "0.021056815", "0.005035325",
"0.030669709", "0.027465411", "0.043486901", "0.017852517", "0.005035325",
"0.024261113", "0", "0", "0.001831027", "0.014648219", "0", "0.017852517",
"0.037078305", NA, NA, NA, "0.027465411", NA, "0.008239623",
"0.046691199", "0.088347072", "0.011443921", "0.008239623", "0.033874007",
NA, "0.037078305", "0.011443921", "0.014648219", "0", "0.024261113",
"0.005035325", "0.005035325", "0.296626438", "0.053099794", "0.017852517",
"0.040282603", "0.001831027", "0", "0", NA, "0.004881939", NA,
"0.011095317", "0.032842138", "0.042162204", "0.017308694", "0.032842138",
"0.014202006", NA, "0.00183211", "0", "0.033894034", "0.046718803",
"0.011450687", "0.040306418", "0.037100226", "0.017863072", "0.030687841",
"0", "0", "0.00183211", "0", "0", NA, "0.007988628", "0.091869224",
NA, NA, NA, "0.024275457", "0.00183211", NA, NA, NA, "0", NA,
"0", "0", NA, "0", "0", "0", NA, "0.005038302", "0", "0.242296538",
"0", "0", "0", "0", "0", "0.033894034", "0.00183211", "0.005038302",
"0.017863072", "0.030687841", "0", "0.153675746", NA, "0.020562248",
"0.007575565", "0.008657789", "0.011904459", "0.001082224", "0.006493341",
"0.011904459", "0.006493341", "0.018397801", "0.010822236", "0.017315577",
"0.011904459", "0.020562248", "0.041124495", NA, NA, NA, "0.014068906",
"0.067097861", "0.004328894", "0.006493341", "0.002164447", "0.038960048",
"0.020562248", "0.019480024", NA, NA, "1.311886266", NA, "2.046087257",
"2.139996686", "0.295956988", "1.343189409", "2.088773361", "2.029012815",
"1.579385852", "1.272045902", "1.6676038", "0.130904053", "1.838348217",
"2.003401153", "2.066007439", "2.108693543", "2.677841597", "2.071698919",
"2.048932997", NA, NA, NA, "0.700052107", NA, "0.017074442",
"0.073989247", NA, "1.072844083", "1.109838707", "0.093156627",
NA, "0.069599779", NA, NA, "0.048184462", "0.103864285", "0.099581222",
"0.098510456", "0.091015095", "0", "0.014990722", "0.18738402",
"0.244134608", "0.301955963", "0.239851545", NA, "0.085661266",
NA, "0.01284919", "0", NA, "0.029981443", "0.005353829", "0.67458247",
"0.033193741", "0.032122975", NA, NA, NA, NA, "0.012553306",
NA, NA, NA, NA, NA, "0", "0.028244939", "0.034521592", "0.059628204",
NA, "0.056489878", "0.028244939", "0.062766531", NA, "0.018829959",
NA, "0.003138327", NA, NA, "0.028244939", "0", "0.382875839",
"0.009221717", NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "0",
"0", "0", "0", NA, "0", NA, NA, NA, "0.003073906", NA, "0", "0",
NA, "0.015369529", "0", NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA,
NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, "2", "1"),
`Sample type` = c("K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18",
"K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18",
"K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18",
"K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18",
"K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18",
"K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18",
"K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18",
"K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18",
"K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18",
"K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18",
"K2SO4_18", "K2SO4_18", "K2SO4_18", "K2SO4_18", "H2O_18",
"H2O_18", "H2O_18", "H2O_18", "H2O_18", "H2O_18", "H2O_18",
"H2O_18", "H2O_18", "H2O_18", "H2O_18", "H2O_18", "H2O_18",
"H2O_18", "H2O_18", "H2O_18", "H2O_18", "H2O_18", "H2O_18",
"H2O_18", "H2O_18", "H2O_18", "H2O_18", "H2O_18", "H2O_18",
"H2O_18", "H2O_18", "H2O_18", "H2O_18", "H2O_18", "H2O_18",
"H2O_18", "H2O_18", "H2O_18", "H2O_18", "H2O_18", "H2O_18",
"H2O_18", "H2O_18", "H2O_18", "H2O_18", "H2O_18", "H2O_18",
"H2O_18", "H2O_18", "H2O_18", "H2O_18", "H2O_18", "H2O_18",
"H2O_18", "H2O_18", "H2O_18", "H2O_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18", "Vac_18",
"Vac_18", "Vac_18", "Vac_18", "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, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0), Date2 = structure(c(17686, 17686, 17686,
17686, 17686, 17686, 17686, 17686, 17686, 17686, 17686, 17686,
17686, 17686, 17686, 17686, 17686, 17686, 17686, 17686, 17686,
17686, 17686, 17686, 17691, 17691, 17691, 17691, 17691, 17708,
17708, 17708, 17708, 17708, 17708, 17708, 17708, 17735, 17735,
17735, 17735, 17735, 17735, 17735, 17735, 17763, 17763, 17763,
17763, 17763, 17763, 17763, 17763, 17686, 17686, 17686, 17686,
17686, 17686, 17686, 17686, 17686, 17686, 17686, 17686, 17686,
17686, 17686, 17686, 17686, 17686, 17686, 17686, 17686, 17686,
17686, 17686, 17691, 17691, 17691, 17691, 17691, 17708, 17708,
17708, 17708, 17708, 17708, 17708, 17708, 17735, 17735, 17735,
17735, 17735, 17735, 17735, 17735, 17763, 17763, 17763, 17763,
17763, 17763, 17763, 17763, 17682, 17682, 17682, 17682, 17682,
17682, 17682, 17682, 17682, 17682, 17682, 17682, 17682, 17682,
17682, 17682, 17682, 17682, 17682, 17682, 17682, 17682, 17682,
17682, 17682, 17682, 17682, 17682, 17682, 17691, 17691, 17691,
17691, 17691, 17691, 17691, 17691, 17691, 17691, 17691, 17691,
17691, 17691, 17691, 17691, 17691, 17691, 17691, 17691, 17691,
17691, 17691, 17691, 17691, 17691, 17691, 17691, 17691, 17698,
17698, 17698, 17698, 17698, 17698, 17698, 17698, 17698, 17698,
17698, 17698, 17698, 17698, 17698, 17698, 17698, 17698, 17698,
17698, 17698, 17698, 17698, 17698, 17698, 17698, 17698, 17698,
17698, 17703, 17703, 17703, 17703, 17703, 17703, 17703, 17703,
17703, 17703, 17703, 17703, 17703, 17703, 17703, 17703, 17703,
17703, 17703, 17703, 17703, 17703, 17703, 17703, 17703, 17703,
17703, 17703, 17703, 17708, 17708, 17708, 17708, 17708, 17708,
17708, 17708, 17710, 17710, 17710, 17710, 17710, 17710, 17710,
17710, 17710, 17710, 17710, 17710, 17710, 17710, 17710, 17710,
17710, 17710, 17710, 17710, 17710, 17718, 17718, 17718, 17718,
17718, 17718, 17718, 17718, 17718, 17718, 17718, 17718, 17718,
17718, 17718, 17718, 17718, 17718, 17718, 17718, 17718, 17718,
17718, 17718, 17718, 17718, 17718, 17718, 17718, 17726, 17726,
17726, 17726, 17726, 17726, 17726, 17726, 17726, 17726, 17726,
17726, 17726, 17726, 17726, 17726, 17726, 17726, 17726, 17726,
17726, 17726, 17726, 17726, 17726, 17726, 17726, 17726, 17726,
17732, 17732, 17732, 17732, 17732, 17732, 17732, 17732, 17732,
17732, 17732, 17732, 17732, 17732, 17732, 17732, 17732, 17732,
17732, 17732, 17732, 17735, 17735, 17735, 17735, 17735, 17735,
17735, 17735, 17740, 17740, 17740, 17740, 17740, 17740, 17740,
17740, 17740, 17740, 17740, 17740, 17740, 17740, 17740, 17740,
17740, 17740, 17740, 17740, 17740, 17740, 17740, 17740, 17740,
17740, 17740, 17740, 17740, 17747, 17747, 17747, 17747, 17747,
17747, 17747, 17747, 17747, 17747, 17747, 17747, 17747, 17747,
17747, 17747, 17747, 17747, 17747, 17747, 17747, 17747, 17747,
17747, 17747, 17747, 17747, 17747, 17747, 17752, 17752, 17752,
17752, 17752, 17752, 17752, 17752, 17752, 17752, 17752, 17752,
17752, 17752, 17752, 17752, 17752, 17752, 17752, 17752, 17752,
17752, 17752, 17752, 17752, 17752, 17752, 17752, 17752, 17759,
17759, 17759, 17759, 17759, 17759, 17759, 17759, 17759, 17759,
17759, 17759, 17759, 17759, 17759, 17759, 17759, 17759, 17759,
17759, 17759, 17759, 17759, 17759, 17759, 17759, 17759, 17759,
17759, 17763, 17763, 17763, 17763, 17763, 17763, 17763, 17763,
17767, 17767, 17767, 17767, 17767, 17767, 17767, 17767, 17767,
17767, 17767, 17767, 17767, 17767, 17767, 17767, 17767, 17767,
17767, 17767, 17767, 17767, 17767, 17767, 17767, 17767, 17767,
17767, 17767, NA, NA), class = "Date")), .Names = c("value",
"Sample type", "Z", "Date2"), class = "data.frame", row.names = c(NA,
-493L))
我使用以下代码制作图表:
p<-ggplot(ZNH2, aes(ZNH2$Date2,ZNH2$value,color=ZNH2$`Sample type`, na.rm=T))+
stat_summary(fun.y = mean,geom = "point",lwd=6) +
stat_summary(fun.y = mean,geom = "line",lwd=2) +
stat_summary(fun.data = mean_se, geom = "errorbar", lwd=1.5, width = 1)
在尝试添加阴影区域时,我遇到了问题,因为每一行都有可变长度的数据,无论我如何尝试设置它,我都会收到错误消息。我尝试过使用 geom_rect、geom_polygon、geom_ribbon 和其他几个。我可以使用帮助来了解如何在 ggplot 中设置任何能够着色的函数。
下图是我目前拥有的图表。尝试在绿色和红色、红色和蓝色以及蓝色和 x 轴之间以不同颜色着色