理解ggpmisc包中find_peaks函数的忽略阈值参数在IT技术中的含义

3

我无法理解忽略阈值参数,我想画出明显的峰值。但我想对这个参数有更好的理解。文档中说:“在0.0和1.0之间的数值,表示峰值低于此阈值将被忽略。”

我无法理解这句话。

structure(list(x = c(-0.977307904440207, -0.966859928297583, 
-0.95641195215496, -0.945963976012337, -0.935515999869714, -0.925068023727091, 
-0.914620047584468, -0.904172071441845, -0.893724095299222, -0.883276119156599, 
-0.872828143013975, -0.862380166871352, -0.851932190728729, -0.841484214586106, 
-0.831036238443483, -0.82058826230086, -0.810140286158237, -0.799692310015614, 
-0.789244333872991, -0.778796357730367, -0.768348381587744, -0.757900405445121, 
-0.747452429302498, -0.737004453159875, -0.726556477017252, -0.716108500874629, 
-0.705660524732006, -0.695212548589383, -0.684764572446759, -0.674316596304136, 
-0.663868620161513, -0.65342064401889, -0.642972667876267, -0.632524691733644, 
-0.622076715591021, -0.611628739448397, -0.601180763305774, -0.590732787163151, 
-0.580284811020528, -0.569836834877905, -0.559388858735282, -0.548940882592659, 
-0.538492906450036, -0.528044930307413, -0.517596954164789, -0.507148978022166, 
-0.496701001879543, -0.48625302573692, -0.475805049594297, -0.465357073451674, 
-0.454909097309051, -0.444461121166428, -0.434013145023805, -0.423565168881181, 
-0.413117192738558, -0.402669216595935, -0.392221240453312, -0.381773264310689, 
-0.371325288168066, -0.360877312025443, -0.35042933588282, -0.339981359740196, 
-0.329533383597573, -0.31908540745495, -0.308637431312327, -0.298189455169704, 
-0.287741479027081, -0.277293502884458, -0.266845526741835, -0.256397550599212, 
-0.245949574456588, -0.235501598313965, -0.225053622171342, -0.214605646028719, 
-0.204157669886096, -0.193709693743473, -0.18326171760085, -0.172813741458227, 
-0.162365765315603, -0.15191778917298, -0.141469813030357, -0.131021836887734, 
-0.120573860745111, -0.110125884602488, -0.0996779084598648, 
-0.0892299323172416, -0.0787819561746186, -0.0683339800319954, 
-0.0578860038893723, -0.0474380277467492, -0.0369900516041261, 
-0.026542075461503, -0.0160940993188798, -0.00564612317625668, 
0.00480185296636637, 0.0152498291089895, 0.0256978052516126, 
0.0361457813942359, 0.0465937575368589, 0.057041733679482, 0.067489709822105, 
0.0779376859647283, 0.0883856621073513, 0.0988336382499744, 0.109281614392598, 
0.119729590535221, 0.130177566677844, 0.140625542820467, 0.15107351896309, 
0.161521495105713, 0.171969471248336, 0.182417447390959, 0.192865423533582, 
0.203313399676206, 0.213761375818829, 0.224209351961452, 0.234657328104075, 
0.245105304246698, 0.255553280389321, 0.266001256531944, 0.276449232674568, 
0.286897208817191, 0.297345184959814, 0.307793161102437, 0.31824113724506, 
0.328689113387683, 0.339137089530306, 0.349585065672929, 0.360033041815552, 
0.370481017958175, 0.380928994100799, 0.391376970243422, 0.401824946386045, 
0.412272922528668, 0.422720898671291, 0.433168874813914, 0.443616850956537, 
0.454064827099161, 0.464512803241784, 0.474960779384407, 0.48540875552703, 
0.495856731669653, 0.506304707812276, 0.516752683954899, 0.527200660097522, 
0.537648636240145, 0.548096612382768, 0.558544588525392, 0.568992564668015, 
0.579440540810638, 0.589888516953261, 0.600336493095884, 0.610784469238507, 
0.62123244538113, 0.631680421523753, 0.642128397666377, 0.652576373809, 
0.663024349951623, 0.673472326094246, 0.683920302236869, 0.694368278379492, 
0.704816254522115, 0.715264230664738, 0.725712206807362, 0.736160182949985, 
0.746608159092608, 0.757056135235231, 0.767504111377854, 0.777952087520477, 
0.7884000636631, 0.798848039805723, 0.809296015948346, 0.819743992090969, 
0.830191968233593, 0.840639944376216, 0.851087920518839, 0.861535896661462, 
0.871983872804085, 0.882431848946708, 0.892879825089332, 0.903327801231955, 
0.913775777374578, 0.924223753517201, 0.934671729659824, 0.945119705802447, 
0.95556768194507, 0.966015658087693, 0.976463634230316, 0.986911610372939, 
0.997359586515563, 1.00780756265819, 1.01825553880081, 1.02870351494343, 
1.03915149108606, 1.04959946722868, 1.0600474433713, 1.07049541951392, 
1.08094339565655, 1.09139137179917, 1.10183934794179, 1.11228732408442, 
1.12273530022704, 1.13318327636966, 1.14363125251229, 1.15407922865491, 
1.16452720479753, 1.17497518094016, 1.18542315708278, 1.1958711332254, 
1.20631910936802, 1.21676708551065, 1.22721506165327, 1.23766303779589, 
1.24811101393852, 1.25855899008114, 1.26900696622376, 1.27945494236639, 
1.28990291850901, 1.30035089465163, 1.31079887079426, 1.32124684693688, 
1.3316948230795, 1.34214279922213, 1.35259077536475, 1.36303875150737, 
1.37348672764999, 1.38393470379262, 1.39438267993524, 1.40483065607786, 
1.41527863222049, 1.42572660836311, 1.43617458450573, 1.44662256064836, 
1.45707053679098, 1.4675185129336, 1.47796648907623, 1.48841446521885, 
1.49886244136147, 1.5093104175041, 1.51975839364672, 1.53020636978934, 
1.54065434593196, 1.55110232207459, 1.56155029821721, 1.57199827435983, 
1.58244625050246, 1.59289422664508, 1.6033422027877, 1.61379017893033, 
1.62423815507295, 1.63468613121557, 1.6451341073582, 1.65558208350082, 
1.66603005964344, 1.67647803578607, 1.68692601192869, 1.69737398807131, 
1.70782196421393, 1.71826994035656, 1.72871791649918, 1.7391658926418, 
1.74961386878443, 1.76006184492705, 1.77050982106967, 1.7809577972123, 
1.79140577335492, 1.80185374949754, 1.81230172564017, 1.82274970178279, 
1.83319767792541, 1.84364565406804, 1.85409363021066, 1.86454160635328, 
1.8749895824959, 1.88543755863853, 1.89588553478115, 1.90633351092377, 
1.9167814870664, 1.92722946320902, 1.93767743935164, 1.94812541549427, 
1.95857339163689, 1.96902136777951, 1.97946934392214, 1.98991732006476, 
2.00036529620738, 2.01081327235001, 2.02126124849263, 2.03170922463525, 
2.04215720077787, 2.0526051769205, 2.06305315306312, 2.07350112920574, 
2.08394910534837, 2.09439708149099, 2.10484505763361, 2.11529303377624, 
2.12574100991886, 2.13618898606148, 2.14663696220411, 2.15708493834673, 
2.16753291448935, 2.17798089063198, 2.1884288667746, 2.19887684291722, 
2.20932481905984, 2.21977279520247, 2.23022077134509, 2.24066874748771, 
2.25111672363034, 2.26156469977296, 2.27201267591558, 2.28246065205821, 
2.29290862820083, 2.30335660434345, 2.31380458048608, 2.3242525566287, 
2.33470053277132, 2.34514850891394, 2.35559648505657, 2.36604446119919, 
2.37649243734181, 2.38694041348444, 2.39738838962706, 2.40783636576968, 
2.41828434191231, 2.42873231805493, 2.43918029419755, 2.44962827034018, 
2.4600762464828, 2.47052422262542, 2.48097219876805, 2.49142017491067, 
2.50186815105329, 2.51231612719591, 2.52276410333854, 2.53321207948116, 
2.54366005562378, 2.55410803176641, 2.56455600790903, 2.57500398405165, 
2.58545196019428, 2.5958999363369, 2.60634791247952, 2.61679588862215, 
2.62724386476477, 2.63769184090739, 2.64813981705001, 2.65858779319264, 
2.66903576933526, 2.67948374547788, 2.68993172162051, 2.70037969776313, 
2.71082767390575, 2.72127565004838, 2.731723626191, 2.74217160233362, 
2.75261957847625, 2.76306755461887, 2.77351553076149, 2.78396350690412, 
2.79441148304674, 2.80485945918936, 2.81530743533199, 2.82575541147461, 
2.83620338761723, 2.84665136375985, 2.85709933990248, 2.8675473160451, 
2.87799529218772, 2.88844326833035, 2.89889124447297, 2.90933922061559, 
2.91978719675822, 2.93023517290084, 2.94068314904346, 2.95113112518609, 
2.96157910132871, 2.97202707747133, 2.98247505361396, 2.99292302975658, 
3.0033710058992, 3.01381898204182, 3.02426695818445, 3.03471493432707, 
3.04516291046969, 3.05561088661232, 3.06605886275494, 3.07650683889756, 
3.08695481504019, 3.09740279118281, 3.10785076732543, 3.11829874346806, 
3.12874671961068, 3.1391946957533, 3.14964267189592, 3.16009064803855, 
3.17053862418117, 3.18098660032379, 3.19143457646642, 3.20188255260904, 
3.21233052875166, 3.22277850489429, 3.23322648103691, 3.24367445717953, 
3.25412243332216, 3.26457040946478, 3.2750183856074, 3.28546636175003, 
3.29591433789265, 3.30636231403527, 3.31681029017789, 3.32725826632052, 
3.33770624246314, 3.34815421860576, 3.35860219474839, 3.36905017089101, 
3.37949814703363, 3.38994612317626, 3.40039409931888, 3.4108420754615, 
3.42129005160413, 3.43173802774675, 3.44218600388937, 3.45263398003199, 
3.46308195617462, 3.47352993231724, 3.48397790845986, 3.49442588460249, 
3.50487386074511, 3.51532183688773, 3.52576981303036, 3.53621778917298, 
3.5466657653156, 3.55711374145823, 3.56756171760085, 3.57800969374347, 
3.5884576698861, 3.59890564602872, 3.60935362217134, 3.61980159831397, 
3.63024957445659, 3.64069755059921, 3.65114552674183, 3.66159350288446, 
3.67204147902708, 3.6824894551697, 3.69293743131233, 3.70338540745495, 
3.71383338359757, 3.7242813597402, 3.73472933588282, 3.74517731202544, 
3.75562528816807, 3.76607326431069, 3.77652124045331, 3.78696921659593, 
3.79741719273856, 3.80786516888118, 3.8183131450238, 3.82876112116643, 
3.83920909730905, 3.84965707345167, 3.8601050495943, 3.87055302573692, 
3.88100100187954, 3.89144897802217, 3.90189695416479, 3.91234493030741, 
3.92279290645004, 3.93324088259266, 3.94368885873528, 3.9541368348779, 
3.96458481102053, 3.97503278716315, 3.98548076330577, 3.9959287394484, 
4.00637671559102, 4.01682469173364, 4.02727266787627, 4.03772064401889, 
4.04816862016151, 4.05861659630414, 4.06906457244676, 4.07951254858938, 
4.089960524732, 4.10040850087463, 4.11085647701725, 4.12130445315987, 
4.1317524293025, 4.14220040544512, 4.15264838158774, 4.16309635773037, 
4.17354433387299, 4.18399231001561, 4.19444028615824, 4.20488826230086, 
4.21533623844348, 4.22578421458611, 4.23623219072873, 4.24668016687135, 
4.25712814301397, 4.2675761191566, 4.27802409529922, 4.28847207144184, 
4.29892004758447, 4.30936802372709, 4.31981599986971, 4.33026397601234, 
4.34071195215496, 4.35115992829758, 4.36160790444021), y = c(9.35467335825542e-05, 
0.000138378592517131, 0.000200679044523461, 0.000285444802972483, 
0.000398410332040533, 0.000545922275878648, 0.000734720330203274, 
0.000976823443940335, 0.00127671339044658, 0.00163686397136291, 
0.00205936648426705, 0.00254338707458654, 0.00308458038832779, 
0.00367466622053721, 0.00430123317989432, 0.00494782665895227, 
0.00559392074888324, 0.00620978907036041, 0.00677115695721494, 
0.00725506284891618, 0.00764172113764005, 0.00791625177154416, 
0.00807021783523942, 0.00810287345705189, 0.0080220449184385, 
0.00784459093117532, 0.00759458408013685, 0.00731731596071467, 
0.00706235765275206, 0.00688071544325104, 0.0068276616963521, 
0.00696155381456414, 0.00734282187737365, 0.00803319242197537, 
0.00909520859905438, 0.010592100596787, 0.0126619289501642, 0.0153217211802535, 
0.0186411885283858, 0.0227003960969921, 0.027589758345995, 0.0334133442403829, 
0.0402922761614071, 0.0483679328719644, 0.0578045999350757, 0.068879688860835, 
0.0819188863781823, 0.0970351178520946, 0.114479191700967, 0.134497243813785, 
0.157314433398521, 0.183115691183027, 0.212024282530228, 0.244079216533309, 
0.279212795353508, 0.317477337134002, 0.358199670921826, 0.400727196301791, 
0.444346292294268, 0.48822398615096, 0.531440309664528, 0.573029756903955, 
0.612029892851845, 0.64753456079567, 0.678617012395876, 0.704192654921931, 
0.724422475364781, 0.739264018675711, 0.748924793573328, 0.753845861094766, 
0.754671658286855, 0.752208613415348, 0.747375674202298, 0.741150308534282, 
0.734571739279015, 0.728743129118981, 0.724452669685307, 0.722335416378488, 
0.722880380882211, 0.72642998314238, 0.733186681575962, 0.743224909775993, 
0.756506411380135, 0.772908492880401, 0.792525064061053, 0.814654859373671, 
0.838950561327388, 0.865028977860331, 0.89247720491481, 0.920858085472586, 
0.949715602087053, 0.978580778678401, 1.00697858740696, 1.03434867046031, 
1.06011769192159, 1.08394406309373, 1.10546473134278, 1.12438028680665, 
1.14046834158879, 1.15359542726619, 1.16372665281937, 1.17093237226502, 
1.175391132401, 1.17716864040466, 1.17697452460083, 1.17535156113978, 
1.17284261161468, 1.17000578563482, 1.1673822262804, 1.16546244036158, 
1.16465295456254, 1.16524526089255, 1.16744328885454, 1.17127545278178, 
1.17632359943404, 1.18216317300258, 1.18824102198632, 1.19391015507267, 
1.19847090944391, 1.20121566697414, 1.20147401226351, 1.19865509483284, 
1.19192809561553, 1.18113079061029, 1.16631484017115, 1.14753053064945, 
1.12495317241856, 1.09885768994165, 1.06959072283289, 1.03754313080949, 
1.00312554791051, 0.966728519750222, 0.928660299591921, 0.889530808583166, 
0.849714415390239, 0.809589688955618, 0.769547347253603, 0.729994718341219, 
0.691355293884662, 0.65406254668032, 0.618547799450208, 0.585402247608208, 
0.555041771722594, 0.527579127974952, 0.503166717710311, 0.481845379041531, 
0.463540663434946, 0.448066510960296, 0.435135969896367, 0.424378149597792, 
0.415360176557574, 0.407694284377986, 0.400697004250687, 0.393922390015123, 
0.386985944131214, 0.379566612803809, 0.371413955708176, 0.362350469632623, 
0.352269565811249, 0.341129900193552, 0.328902629353716, 0.315633605987442, 
0.301521542585101, 0.286694684917694, 0.271293051221101, 0.255463378424863, 
0.239355625337771, 0.223120708193214, 0.206909073437322, 0.19086966898118, 
0.175198868753046, 0.160039113509531, 0.145509642810717, 0.131727929995761, 
0.1187962495981, 0.10679912500712, 0.0958015744784178, 0.0858483481813833, 
0.0769642498945394, 0.0691807092513523, 0.0625723565097088, 0.0569943879153287, 
0.0524097745014153, 0.048774859788882, 0.0460403598670048, 0.0441516318943401, 
0.04304836483602, 0.0426639080579755, 0.0429244997812627, 0.0437840404964467, 
0.0451182402282176, 0.0467989803380999, 0.0487244406024663, 0.0507922088957852, 
0.0529022355002754, 0.0549597503422944, 0.0568779327180154, 0.0585801541997996, 
0.0600012055331445, 0.0610403226339544, 0.0617022059092868, 0.061966992332567, 
0.0618257173286429, 0.0612789702136134, 0.0603354952659015, 0.059010828794266, 
0.0573260478974196, 0.0553066912439171, 0.0529670124651277, 0.0503416223622914, 
0.0474895470199534, 0.0444492210235703, 0.0412614108671463, 0.0379690444884631, 
0.0346168654174133, 0.0312508598068006, 0.0279174277909384, 0.0246622965112231, 
0.0215481586184699, 0.0186087827067186, 0.0158730035706386, 0.0133652638941858, 
0.0111022914331363, 0.00909286866151481, 0.00733802056602584, 
0.00583159532563757, 0.00456118812397254, 0.00351582349236138, 
0.00268235199669189, 0.00201575468667243, 0.00149251264074435, 
0.00109022189648132, 0.000788374198815222, 0.000568925940456925, 
0.000416670088275593, 0.000319432558890428, 0.000268119285696728, 
0.000259881352375388, 0.000289901597574823, 0.000356891454861054, 
0.00046321406083737, 0.000612711078410104, 0.000810175195195916, 
0.00106074426865979, 0.00136922175594418, 0.0017393358725823, 
0.00217365160884232, 0.00267722204086709, 0.0032361100186413, 
0.00383985992229101, 0.00447381839253418, 0.00511945291288203, 
0.00575501721547927, 0.00635654528710867, 0.00689913123606773, 
0.00735842862349722, 0.00770397004220343, 0.00791515916471235, 
0.00798959450311985, 0.00792468795089921, 0.0077248607029855, 
0.00740123031604458, 0.00697087208234988, 0.00645572849253641, 
0.00588126068059053, 0.00527495191639691, 0.00466839612032965, 
0.00409211541598707, 0.00356925806524492, 0.00311964067830613, 
0.00275944805542701, 0.00250111926357269, 0.00235335897581965, 
0.00232121238786562, 0.00240614741859463, 0.00261076101275212, 
0.00293204103219015, 0.00334856835864746, 0.00384532240749714, 
0.00440369389469677, 0.00500185743626895, 0.00561541318377006, 
0.00621831287008987, 0.00678406019012477, 0.00728714879393812, 
0.00769420357908674, 0.00799108947703486, 0.00817200806139797, 
0.00823577922921987, 0.0081890019525581, 0.00804570958926608, 
0.00782647218231045, 0.00755699244308247, 0.00726627382973253, 
0.0069853531480466, 0.00675099050970175, 0.00658435894504438, 
0.00650081170782827, 0.00650774188827459, 0.00660410780225739, 
0.00678057552943809, 0.00702025971239145, 0.00730001306972794, 
0.00759218585900812, 0.00786268016064849, 0.00807650050184691, 
0.00820997422890116, 0.00824414792030346, 0.00816714935927627, 
0.00797486689650825, 0.00767106791196589, 0.00726698267955546, 
0.00678041018535105, 0.00623443059795494, 0.00565643256560351, 
0.00508301902454231, 0.00454206907122028, 0.00405918482568285, 
0.00365670501914952, 0.00335292648633556, 0.00316154673510228, 
0.00309129575380564, 0.00314572147613879, 0.00332912029336608, 
0.00363427527815798, 0.0040368230327672, 0.00451741952181655, 
0.00505273022515262, 0.00561625385718934, 0.00617937631848977, 
0.00671263553319174, 0.00718715645003618, 0.00757619388467813, 
0.00784280030491123, 0.0079777824927851, 0.00797616099892788, 
0.0078375245753603, 0.00756843561287485, 0.0071817597107811, 
0.00669560683423435, 0.00613197027492077, 0.00551516756645796, 
0.00487019342471168, 0.00422492844960509, 0.00360203391762665, 
0.00301754758332799, 0.00248332992453507, 0.00200707134879243, 
0.00159256322326052, 0.00124017244806206, 0.000947455700613503, 
0.000709848542735665, 0.000524853525021908, 0.000382431350915808, 
0.000273614002512794, 0.000192125018364281, 0.000132337341075087, 
8.93783405607899e-05, 5.91619890527444e-05, 3.8365130224513e-05, 
2.43642070010061e-05, 1.51743369497939e-05, 9.49700925888656e-06, 
5.82491739230106e-06, 3.49920544917502e-06, 2.05783657050533e-06, 
1.18422845037845e-06, 6.6667365056193e-07, 3.67128026396043e-07, 
1.97900779880222e-07, 1.04785251724885e-07, 5.66975977666674e-08, 
3.30678882447888e-08, 2.34259687227164e-08, 2.46641072007813e-08, 
3.75583085754877e-08, 6.71314075793532e-08, 1.24066076931159e-07, 
2.27400705770364e-07, 4.0887095432408e-07, 7.19395823110606e-07, 
1.28546397910116e-06, 2.2564133461593e-06, 3.87450629709357e-06, 
6.50992875346683e-06, 1.07064709172089e-05, 1.72424305884128e-05, 
2.72037140499891e-05, 4.20682301824456e-05, 6.3799428587674e-05, 
9.54971398439128e-05, 0.00014193361726917, 0.000206671450945137, 
0.000294943976843194, 0.000412701681643711, 0.000566437243726867, 
0.000762905501255222, 0.00100873220466962, 0.00130991272036685, 
0.0016712101006953, 0.00210137680565559, 0.00259558562556288, 
0.00314617374152246, 0.00374360115964364, 0.00437409070835309, 
0.00501986880771741, 0.00565974447124103, 0.00627002113517276, 
0.00682571185071731, 0.00730006076630766, 0.00765703832483032, 
0.00788896518383927, 0.00798497679300017, 0.00794080505945791, 
0.00775901982741821, 0.0074487857816721, 0.00702516601093132, 
0.00650803250761185, 0.00592066989985584, 0.00528711531493085, 
0.00463811449371955, 0.00399836344992333, 0.0033866417711127, 
0.00281776221924679, 0.00230233581415345, 0.00184684298012908, 
0.00145396169666484, 0.00112309413355253, 0.000851026777322083, 
0.000638469881728235, 0.000471565452291449, 0.000343546515501986, 
0.000248234727853222, 0.000180161133229032, 0.000134807422615991, 
0.000108771670293329, 9.98734069091446e-05, 0.000107212238143034, 
0.000132160044127707, 0.000177733440561024, 0.000246170943046168, 
0.000342159765380993, 0.000471283310510395, 0.000639741947955054, 
0.000853977194654879, 0.00112019571948804, 0.00144379740679273, 
0.00182872049525451, 0.00228305882179099, 0.00279903764472115, 
0.00336799012787172, 0.00397870254031385, 0.00461580775729695, 
0.0052601686183354, 0.00588959943796559, 0.00647990794520743, 
0.00700621595458693, 0.00744131311502314, 0.00775245646507752, 
0.00793452910967229, 0.00797953619450253, 0.00788635680550173, 
0.00766083633916202, 0.00731541840722602, 0.00686836236027451, 
0.00634261772885912, 0.00576444858777299, 0.00516278067037721, 
0.00457199611148023, 0.00401890898674282, 0.003526389054023, 
0.00311385535769371, 0.00279693706103843, 0.0025873082690359, 
0.00249264103619575, 0.00251662158286031, 0.00265964243267441, 
0.00292946323638958, 0.00330080282831426, 0.00375927491190256, 
0.00428661948579105, 0.00486103459047664, 0.00545774489241557, 
0.00604982643858229, 0.00660928357150105, 0.00710834994950929, 
0.00751413426658035, 0.00779926529784976, 0.00795535029868134, 
0.00797432349584143, 0.00785509907667289, 0.00760348354635287, 
0.00723163122026488, 0.00675709133349726, 0.00620152126786393, 
0.00558916359471299, 0.00494505693934328, 0.00429964728069529, 
0.0036737778531124, 0.00308409373795901, 0.00254312645193455, 
0.00205923006693437, 0.00163679419558235, 0.00127667852037028, 
0.000976806419778256, 0.00073471205118031, 0.000545918161281267, 
0.000398408342105763, 0.000285443866083208, 0.000200678614955062, 
0.000138378400645148, 9.35466500698836e-05)), class = "data.frame", row.names = c(NA, 
-512L))

代码

plot(df)
peak_x_val <- x[ggpmisc:::find_peaks(y,ignore_threshold = 0.3)]
peaks <- y[ggpmisc:::find_peaks(y,ignore_threshold = 0.3)]
ggplot(data = data.frame(x, y), aes(x = x, y = y)) + geom_line() + stat_peaks(col = "red",ignore_threshold = 0.3) 

enter image description here

1个回答

3

寻找峰值的算法最终来自于Fortran代码,定义在这里。它由splus2R::peaks调用,后者又被ggpmisc:::find_peaks调用,而这是ggpmisc::stat_peaks使用的函数。寻找峰值的算法相当简单,实际上只是查找曲线的一阶导数为0且二阶导数为负的点。这将找到数据中的每一个小正尖峰以及您想称之为“峰”的东西。我们可以通过将ignore_threshold参数设置为0来查看其原始输出:

ggplot(df, aes(x, y)) + 
  geom_line() +
  ggpmisc::stat_peaks(col = "red", ignore_threshold = 0) 

enter image description here

然而,为了获得更多控制,ggpmisc:::find_peaks函数需要使用ignore_threshold参数,并将其乘以您的数据范围。如果任何峰值低于此值,则会将其删除。

例如,在您的数据中,我们可以看到有9个小峰值都在y=0.125以下,这大约是您y范围的1/10。因此,如果我们将ignore_threshold设置为0.1,则应该只剩下三个峰值。我们可以绘制一条水平线来显示所有峰值都被删除的水平线以下的级别:

threshold <- 0.1

ggplot(df, aes(x, y)) + 
  geom_line() +
  geom_hline(aes(yintercept = threshold * diff(range(y)) + min(y))) +
  ggpmisc::stat_peaks(col = "red", ignore_threshold = threshold) 

enter image description here

此外,我们可以看到,如果将阈值设置为0.8,则等同于删除任何y值低于1.0左右的峰值,因此我们应该只剩下最高的两个峰值:

threshold <- 0.8

ggplot(df, aes(x, y)) + 
  geom_line() +
  geom_hline(aes(yintercept = threshold * diff(range(y)) + min(y))) +
  ggpmisc::stat_peaks(col = "red", ignore_threshold = threshold) 

enter image description here

最后,经过一些微调,我们可以找到只留下一个点的级别:

threshold <- 0.99

ggplot(df, aes(x, y)) + 
  geom_line() +
  geom_hline(aes(yintercept = threshold * diff(range(y)) + min(y))) +
  ggpmisc::stat_peaks(col = "red", ignore_threshold = threshold) 

enter image description here


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接