2016-12-20 109 views
0

我有兩個系列:情節與細節X軸值中的R

y=c(-1.5998643938095, -1.63502358201045, -1.69216952874043, -1.74137547219013, 
-1.81603466811487, -1.83290876564814, -1.82119795752288, -1.68504242312903, 
-1.64136028883498, -1.5460994846518, -1.53661006904405, -1.52831783563943, 
-1.52603247050589, -1.52268205493272, -1.5212011956198, -1.51432268622967, 
-1.51379366677634, -1.50908788843249, -1.48822428255097, -1.48769228523642, 
-1.48483387454842, -1.48453062065826, -1.48339797802088, -1.48119621507587, 
-1.48110046708904, -1.48060635307086, -1.47995343813638, -1.47994119367829, 
-1.47941156884319, -1.47938925858236, -1.47938695218289, -1.47937696658098, 
-1.47698623662183, -1.47698623662183, -1.47567307555111, -1.47483038921359, 
-1.4736380690598, -1.47292362741829, -1.47215618888986, -1.47149860750148, 
-1.47110996638024, -1.47050643723499, -1.46953281801724, -1.46825152829741, 
-1.46724698190091, -1.46703097959397, -1.46648175185516, -1.4664413436873, 
-1.46607836828396, -1.465853817256, -1.46559489002899, -1.46401962782667, 
-1.46227935977164, -1.46210742960601, -1.46176056274246, -1.46114880053774, 
-1.46050710466594, -1.45930618888587, -1.45930470729008, -1.45880976260809, 
-1.4582337419082, -1.45649254752875, -1.45592179387283, -1.45591600470178, 
-1.45487189856011, -1.45305608952432, -1.45301369078264, -1.45282998956255, 
-1.45264299648548, -1.451492927921, -1.45136310047362, -1.45091392143768, 
-1.45069600456254, -1.45041739845932, -1.45021222131199, -1.45015797613347, 
-1.44855512307855, -1.44786178854079, -1.44781922895741, -1.44771771838997, 
-1.44712449747479, -1.44691700015014, -1.44682684210453, -1.44678284793857, 
-1.44605119420611, -1.4460226868879, -1.44571074258618, -1.4452512583365, 
-1.4451833273209, -1.44347252955088, -1.44346529086636, -1.44334836577964, 
-1.44283234085434, -1.44282090886531, -1.44277303333844, -1.44276726368483, 
-1.44226898300518, -1.44226143122353, -1.44164469533319, -1.44040718820924, 
-1.44007152267034, -1.43891940826629, -1.43878784348646, -1.43720486744441, 
-1.43682534475562, -1.43589722283182, -1.43553231203842, -1.43551864711074, 
-1.43536737759472, -1.43509079079168, -1.4345130019316, -1.43322388529487, 
-1.432492553991, -1.43198101748486, -1.43119406845686, -1.43098345123839, 
-1.43067674410408, -1.43065237690907, -1.4301008969997, -1.42957895243291, 
-1.42913557509501, -1.428764201, -1.428101540577, -1.42690855108318, 
-1.42682882777193, -1.42667868057341, -1.42647659641895, -1.42642967286365, 
-1.42638266289136, -1.42584441450912, -1.42551888935884, -1.42500303556265, 
-1.42480971466621, -1.42267013220422, -1.42267013220422, -1.42254423649875, 
-1.42227372076633, -1.42158579496348, -1.42155981729155, -1.42135043822943, 
-1.42119996091157, -1.42059723196635, -1.42054112251372, -1.42037987610062, 
-1.41988720557195, -1.41846642148337, -1.41768721977366, -1.41712074818823, 
-1.41627221053046, -1.41617302141734, -1.41572980388805, -1.41569378376846, 
-1.41501464816207, -1.41447894688003, -1.4136309327905, -1.41269319137196, 
-1.41244179359642, -1.41174146820488, -1.41160740222662, -1.41087908191835, 
-1.40917254185178, -1.40832530647502, -1.4082042201926, -1.40811332516486, 
-1.40739105306066, -1.40646631308617, -1.40619992858907, -1.40548285389421, 
-1.40432981273198, -1.40395132544927, -1.40330583018292, -1.4018786113105, 
-1.40087144478313, -1.40075829454372, -1.39971935185189, -1.39748597997321, 
-1.39739889942328, -1.39701887658488, -1.39673333360165, -1.39597258502012, 
-1.39527409663982, -1.39527409663982, -1.39521541653476, -1.39494364585368, 
-1.39469676119322, -1.39373022314479, -1.39271653652864, -1.39161201283438, 
-1.39071339847077, -1.38974369953502, -1.38974198938904, -1.3894039853713, 
-1.38873594971682, -1.38871885550179, -1.38706886032285, -1.38511170778675, 
-1.38508010967343, -1.38496145433921, -1.38466062692511, -1.38416734067824, 
-1.3840782779473, -1.38357525629763, -1.38355302746992, -1.38353420843684, 
-1.383388989057, -1.38258701035437, -1.38257742645876, -1.38181544272521, 
-1.38159360170984, -1.38156609412851, -1.38156609412851, -1.38148824778747, 
-1.3805734083841, -1.37970027728057, -1.37955332492153, -1.379454592592, 
-1.37861459579946, -1.37810315557753, -1.37738786297457, -1.37660472268844, 
-1.37651708913807, -1.37642818076612, -1.37623249287843, -1.37574714054356, 
-1.3752624355825, -1.3747435769979, -1.37453801843614, -1.37254136161746, 
-1.37235596806715, -1.3711739927774, -1.37052673385029, -1.37017932312331, 
-1.36919201276548, -1.36874374952405, -1.36870992034192, -1.36844834441028, 
-1.36788940896553, -1.36785426309333, -1.3665578175658, -1.36645921657519, 
-1.36643624494696, -1.36589729865879, -1.36516580262407, -1.36503720674118, 
-1.36489868565419, -1.36481952736318, -1.36395080864832, -1.363101107146, 
-1.36205871878833, -1.36205871878833, -1.36205871878833, -1.36165654176623, 
-1.36089141765738, -1.36029386367878, -1.36017551723156, -1.35999818678069, 
-1.35946012258471, -1.35888403119299, -1.35828482609332, -1.35825234586256, 
-1.3581827654594, -1.35730517576928, -1.35665109196707, -1.35628426072835, 
-1.35490181358604, -1.35397726821586, -1.35334393340595, -1.35190821970445, 
-1.35176594335257, -1.35089065628399, -1.3505684993716, -1.34900490104273, 
-1.34844563384622, -1.34820550365266, -1.34765699737468, -1.34717250009988, 
-1.34694752405214, -1.346257020983, -1.34542246918757, -1.34524213174669, 
-1.34499274521234, -1.34381094932539, -1.34299675617037, -1.34280350149617, 
-1.34087387767563, -1.340820302186, -1.3407666747206, -1.34014217614603, 
-1.33938017259306, -1.33664668609038, -1.33438784936148, -1.33401995755851, 
-1.33219273302297, -1.33164764813041, -1.33130553790835, -1.32349613212725, 
-1.32184064011115, -1.32113456827605, -1.32055011726724, -1.31719895484054, 
-1.31594392214064, -1.31445046615048, -1.31316132337202, -1.31258538304814, 
-1.31112328783767, -1.30942010507318, -1.30935376099677, -1.30711833222081, 
-1.30099326665383, -1.29430541524941, -1.29411365144108, -1.29281795899985, 
-1.28697399928846, -1.28603198919379, -1.27857366187536, -1.27746901606705, 
-1.26691154549586, -1.26671698360671, -1.26354472778279, -1.2603364460369, 
-1.25092528378555, -1.24695579775789, -1.24019070943844, -1.23079299277569, 
-1.22956993851601, -1.22139097947348, -1.16699470736508, -1.15715630822687, 
-1.1138992347869, -1.1120938250391, -1.11149401624673, -1.11061636683127, 
-1.09344632136235, -1.08756453012044, -1.08549289617345, -1.08454018783343, 
-1.07512596404849, -1.07512596404849, -1.0676800449532, -1.06077022887154, 
-1.05993585559515, -1.05954653080575, -1.05877503597449, -1.05104470102228, 
-1.05046086258739, -1.04018538596825, -1.03837204337853, -1.03183636170358, 
-1.02994363068208, -1.01350321426957, -1.00522205124862, -1.00238188834357, 
-1.0004040373221, -0.994823454508715, -0.987020715876091, -0.975102717941364, 
-0.915104263694582) 

和..

x=c(-2.13408282124157, -2.10180387024075, -2.08709542846115, -2.06581854776859, 
-1.96940594614023, -1.92059021455153, -1.77135750098858, -1.44724137769461, 
-1.2561207566961, -1.23337106615069, -1.23337106615069, -1.21033271987616, 
-1.17224190869418, -0.987287130986902, -0.930654101673922, -0.84032098938398, 
-0.804222173279778, -0.710880557798421, -0.710274602839522, -0.645609892110399, 
-0.642339799195257, -0.561068221654604, -0.560578241710363, -0.468376211115928, 
-0.399891346669179, -0.367962749987316, -0.357654677323427, -0.355526612996049, 
-0.351157363516097, -0.339040162099913, -0.32576940070479, -0.31005225147438, 
-0.300801122021865, -0.276367335916672, -0.273291307860379, -0.271941099001061, 
-0.263092638078222, -0.252094919104229, -0.251870071377791, -0.244196231236371, 
-0.242285085575067, -0.238637134733422, -0.237815138595843, -0.237707612367788, 
-0.23432778199568, -0.233217616922032, -0.215005504969912, -0.190866190595962, 
-0.174905786573687, -0.170624208572523, -0.131294039411123, -0.117326122090256, 
-0.117002216501616, -0.102190096136279, -0.0954983190266434, 
-0.0733445959504531, -0.0716155723656131, -0.0680478150792529, 
-0.0630073983523438, -0.0584788679112602, -0.0476709638805417, 
-0.0438622752498619, -0.0437253997185527, -0.0291385761624463, 
-0.0242507098145106, -0.0048903409937795, 0.00974462641756269, 
0.0145813294186947, 0.0191057613829981, 0.0191057613829981, 0.0340295342494246, 
0.0388002234009033, 0.0390062958543158, 0.0439060968485894, 0.0488066270410537, 
0.0581074648913438, 0.0582524295135167, 0.0587023477645277, 0.0794771765507019, 
0.0874941852878619, 0.0942884601795813, 0.0971744448796663, 0.112591008607521, 
0.115842601451899, 0.117777334985236, 0.120771558153887, 0.121770277454725, 
0.131705777270685, 0.136069937654382, 0.138715918637033, 0.146100082885714, 
0.147931378168731, 0.148667996209384, 0.150916408652968, 0.152229184039054, 
0.152311932374882, 0.189979710534138, 0.204491672280449, 0.209335715822045, 
0.212781594082023, 0.228408594592633, 0.243685261274695, 0.249826157122035, 
0.26726146729783, 0.273070276461485, 0.277333935754953, 0.27907302119492, 
0.284122902094142, 0.285831240218903, 0.300744495063032, 0.302615826638597, 
0.316903925614609, 0.320509604802921, 0.322872541898245, 0.330784178217236, 
0.333766357672927, 0.345304107081801, 0.345877256751881, 0.349432731942789, 
0.353197839664365, 0.354444636851614, 0.358851959954376, 0.3658498883919, 
0.373268414067618, 0.38424809747668, 0.388983450149616, 0.394013220107969, 
0.397590808408466, 0.412049695447969, 0.412768116506701, 0.416848382330892, 
0.42027883004796, 0.421508760309064, 0.421527151545797, 0.421645948355298, 
0.42562359144529, 0.427993002373839, 0.427993002373839, 0.434468715001324, 
0.451153129776927, 0.451723596325215, 0.452207713574837, 0.477471014343611, 
0.48536961901946, 0.509554221440034, 0.509990112983694, 0.511967275223757, 
0.513742133279682, 0.524298253524225, 0.544899577957136, 0.563480822566143, 
0.571794602730202, 0.571923720884548, 0.580124428414375, 0.583617519186519, 
0.591790353012289, 0.59196029661932, 0.59641022416288, 0.617442207769692, 
0.620039023859364, 0.620952462500557, 0.639275095589231, 0.657250960061062, 
0.65839848539968, 0.692343534139961, 0.695113023080762, 0.725170528079677, 
0.725320511648619, 0.749589157782804, 0.749770885706225, 0.753784936674951, 
0.772144044737755, 0.789132280758831, 0.789761901470021, 0.794009192254919, 
0.794513883636316, 0.811138663637867, 0.832685174624292, 0.833271275360215, 
0.841995542626672, 0.84738776062292, 0.865301594531753, 0.874522732571248, 
0.875907748464799, 0.885710940918139, 0.890898165782206, 0.894224361543627, 
0.896020924376706, 0.902012952708064, 0.909520128859853, 0.917580402008, 
0.919811467591702, 0.920518946695403, 0.920778343382245, 0.921672761153802, 
0.941624282339792, 0.954859464432611, 0.955646928144893, 0.95757172328681, 
0.96088264590577, 0.962260761219502, 0.978805354690393, 0.980152400103274, 
0.986436341094521, 1.00701910754948, 1.01347603677282, 1.02104466788544, 
1.02327847242141, 1.02505412726133, 1.03096110370269, 1.03693923160162, 
1.04921144723666, 1.04941517861614, 1.05865253464199, 1.07538216096668, 
1.07558813014312, 1.07971110445062, 1.08482603401352, 1.08720790601906, 
1.09986925913665, 1.10222235572373, 1.10535734670845, 1.1068372891502, 
1.11964763689349, 1.13204543352827, 1.13712797493968, 1.137994313651, 
1.14283365452046, 1.15327223047834, 1.16216148806749, 1.16440730747853, 
1.16458533096955, 1.18155509540894, 1.20646482320366, 1.21736715796419, 
1.22135166299098, 1.22205189547215, 1.22486491835871, 1.24031991107987, 
1.25696163373374, 1.26430032405644, 1.26873147674325, 1.27266380857822, 
1.27295500837028, 1.27394783802912, 1.27500526922897, 1.28563176302763, 
1.30001778706583, 1.32102004599264, 1.33852067745566, 1.33988606590512, 
1.34837748840695, 1.37602344513676, 1.38099152137314, 1.39304674741183, 
1.40302514972963, 1.41193674468807, 1.41974582210249, 1.42095571632166, 
1.43652509092991, 1.4408775844686, 1.44555422991457, 1.46029420906855, 
1.46073814063481, 1.46329969139498, 1.46490559979866, 1.46585183789929, 
1.47089773550726, 1.49381967453743, 1.4947688838941, 1.50293745878987, 
1.51953897005108, 1.52493287754767, 1.52752856759917, 1.52900499548279, 
1.53225964130144, 1.53280996843186, 1.5398514209443, 1.54594412948084, 
1.55072368623232, 1.56980436455521, 1.5719982103876, 1.59015951604917, 
1.59721359655012, 1.60687668483233, 1.61297695511031, 1.61443451813017, 
1.63267938631648, 1.63639148926984, 1.64258181632699, 1.65298161250365, 
1.67637046221758, 1.73372533918148, 1.7776936607558, 1.777773570246, 
1.79995468792684, 1.82143061809024, 1.89764633131002, 1.90804519662853, 
1.94921719591175, 2.02385761967456, 2.07464798866137, 2.08044125516482, 
2.17193673385774, 2.19983327769389, 2.22936772843119, 2.2497967207606, 
2.25041829923514, 2.26014008750837, 2.30633809611926, 2.34532730946189, 
2.36846119815433, 2.39824708624861, 2.45599570773836, 2.4590828258477, 
2.46707130963524, 2.4704638806704, 2.48819121085144, 2.51522660432035, 
2.51991090204093, 2.53711294955152, 2.56907217758531, 2.60812454619044, 
2.60956475684073, 2.62822938421567, 2.63585448081955, 2.73357252145678, 
2.76421196010355, 2.77474221788829, 2.86426659827852, 2.8677328167048, 
2.87108136656242, 2.99103441124555, 3.00554690183426, 3.0160909248325, 
3.04462614144865, 3.10435865238545, 3.10449773118004, 3.12367577101729, 
3.13587656152066, 3.13629766043355, 3.15861228566874, 3.15976692019742, 
3.16072755978949, 3.16596254872079, 3.22189824909798, 3.22482598444997, 
3.25247702481879, 3.28793314892395, 3.32070992405156, 3.32109018836231, 
3.4822436996101) 

我要繪製該圖。

plot(y,xaxt="n", type="l") 

我想在這裏與第二系列x的值來填充x軸,但我不想改變圖形的形狀。我嘗試使用軸功能,但我無法完成。

我只是不能做到這一點。

任何幫助?

+2

我想你想'圖(X,Y,...)',繪製你的y值對X的。順便說一下,你應該削減你的問題,並儘量減少,這樣人們可以很容易地理解它並在R中進行測試。 –

+0

[如何指定實際x軸值以繪製R中的x軸刻度] (http://stackoverflow.com/questions/11775692/how-to-specify-the-actual-x-axis-values-to-plot-as-x-axis-ticks-in-r) – emilliman5

+1

你試過什麼在使用'axis'方面?它是如何工作的? – emilliman5

回答

0

您遇到的問題是plot(x, xaxt="n")使x軸範圍從1到長度(y)。當您嘗試將您自己的值與axis(1, at=x)疊加時,您的報價將被放置在x的值範圍內,範圍從-2到3.5 ish。你需要做的是將標籤設置爲x的索引y。

喜歡的東西:

plot(y, xaxt="n") 
axis(1, at=seq_along(y), labels=x) 

現在您的示例數據是相同長度的不那麼這將不會立即生效。

其次,@Tim Biegeleisen的答案更簡單,更漂亮。

0

這是我的建議:

#First, I have to get that the length of "y" and "x" are the same 
y<-head(y,-(length(y)-length(x))) 
#I plot your data 
plot(y, xaxt="n",las=2,type="l") 
#I configure the labels for avoid overlapping 
axis(1, at=seq_along(y), labels=replace(x,rep(c(FALSE,rep(TRUE,7)),length.out=length(y)),""),las=2,cex.axis=0.5) 

enter image description here