1

我有一个数据集如下:

 24     i=6,j=529, Depth Avg
129  1
129.041687011719     1.00000035762787
129.08332824707  .99999988079071
129.125015258789     1.00000011920929
129.166687011719     1.00000023841858
129.20832824707  1.00000035762787
129.250030517578     1.00000047683716
129.29167175293  1.00000035762787
129.333343505859     1.00000011920929
129.375030517578     .999998927116394
129.41667175293  .999999940395355
129.458358764648     1.00000107288361
129.5    1.00000059604645
129.541687011719     1.00000059604645
129.58332824707  1.00000059604645
129.625015258789     .999999284744263
129.666687011719     1.00000095367432
129.70832824707  1.00000107288361
129.750030517578     .999999940395355
129.79167175293  .99999988079071
129.833343505859     1.00000011920929
129.875030517578     1
129.91667175293  .99999988079071
129.958358764648     .999999761581421
 24     i=7,j=505, Depth Avg
129  .999983608722687
129.041687011719     .999982953071594
129.08332824707  .999985218048096
129.125015258789     .999983251094818
129.166687011719     .999989926815033
129.20832824707  .999988317489624
129.250030517578     .999988853931427
129.29167175293  .999985992908478
129.333343505859     .999984502792358
129.375030517578     .999985635280609
129.41667175293  .99998551607132
129.458358764648     .999989748001099
129.5    .999991714954376
129.541687011719     .999998927116394
129.58332824707  .999999225139618
129.625015258789     .999995589256287
129.666687011719     .999993801116943
129.70832824707  .999995410442352
129.750030517578     .999995529651642
129.79167175293  .999992489814758
129.833343505859     .999987006187439
129.875030517578     .999984443187714
129.91667175293  .99998539686203
129.958358764648     .999988079071045
 24     i=6,j=486, Depth Avg
129  .999971926212311
129.041687011719     .999973058700562
129.08332824707  .999974727630615
129.125015258789     .999973118305206
129.166687011719     .999970674514771
129.20832824707  .99997752904892
129.250030517578     .999980330467224
129.29167175293  .999976873397827
129.333343505859     .999974071979523
129.375030517578     .99997091293335
129.41667175293  .999977171421051
129.458358764648     .999985694885254
129.5    .999990105628967
129.541687011719     .999993622303009
129.58332824707  .999999344348907
129.625015258789     .999992668628693
129.666687011719     .999993085861206
129.70832824707  .999992847442627
129.750030517578     .999994277954102
129.79167175293  .999990105628967
129.833343505859     .99998152256012
129.875030517578     .999973177909851
129.91667175293  .999975740909576
129.958358764648     .999980330467224
 24     i=6,j=466, Depth Avg
129  .999960064888
129.041687011719     .999961018562317
129.08332824707  .999964475631714
129.125015258789     .999963104724884
129.166687011719     .999962687492371
129.20832824707  .999969244003296
129.250030517578     .999969959259033
129.29167175293  .999970734119415
129.333343505859     .999963462352753
129.375030517578     .999960005283356
129.41667175293  .999967217445374
129.458358764648     .999975681304932
129.5    .999983072280884
129.541687011719     .999991953372955
129.58332824707  .999997317790985
129.625015258789     .99999213218689
129.666687011719     .999992072582245
129.70832824707  .999985218048096
129.750030517578     .99999064207077
129.79167175293  .999988555908203
129.833343505859     .99997490644455
129.875030517578     .999964952468872
129.91667175293  .999964356422424
129.958358764648     .999969661235809
 24     i=6,j=447, Depth Avg
129  .999943792819977
129.041687011719     .999945878982544
129.08332824707  .999948799610138
129.125015258789     .999946057796478
129.166687011719     .999949932098389
129.20832824707  .999949991703033
129.250030517578     .999954700469971
129.29167175293  .99995630979538
129.333343505859     .999949872493744
129.375030517578     .999945342540741
129.41667175293  .999948680400848
129.458358764648     .999962687492371
129.5    .999973773956299
129.541687011719     .999982416629791
129.58332824707  .999990999698639
129.625015258789     .999992430210114
129.666687011719     .999982595443726
129.70832824707  .999979794025421
129.750030517578     .99998277425766
129.79167175293  .99998414516449
129.833343505859     .999970138072968
129.875030517578     .999956965446472
129.91667175293  .999948382377625
129.958358764648     .999954998493195
 24     i=6,j=427, Depth Avg
129  .999925792217255
129.041687011719     .999931156635284
129.08332824707  .999930560588837
129.125015258789     .999935030937195
129.166687011719     .999935209751129
129.20832824707  .999935805797577
129.250030517578     .999941289424896
129.29167175293  .999940037727356
129.333343505859     .999939382076263
129.375030517578     .999930918216705
129.41667175293  .999935328960419
129.458358764648     .999944567680359
129.5    .999958515167236
129.541687011719     .999973475933075
129.58332824707  .999985992908478
129.625015258789     .999986290931702
129.666687011719     .99998140335083
129.70832824707  .999981462955475
129.750030517578     .999972283840179
129.79167175293  .999978244304657
129.833343505859     .999967753887177
129.875030517578     .999947845935822
129.91667175293  .99993896484375
129.958358764648     .999940454959869
 24     i=6,j=407, Depth Avg
129  .999912023544312
129.041687011719     .999916732311249
129.08332824707  .999918818473816
129.125015258789     .999919652938843
129.166687011719     .999922215938568
129.20832824707  .999927818775177
129.250030517578     .999928176403046
129.29167175293  .99993222951889
129.333343505859     .999927520751953
129.375030517578     .999922752380371
129.41667175293  .99992299079895
129.458358764648     .999931871891022
129.5    .999947428703308
129.541687011719     .999964654445648
129.58332824707  .999975860118866
129.625015258789     .999980509281158
129.666687011719     .999982714653015
129.70832824707  .999972343444824
129.750030517578     .999974310398102
129.79167175293  .99997079372406
129.833343505859     .999962270259857
129.875030517578     .99994570016861
129.91667175293  .999932110309601
129.958358764648     .999929487705231
 24     i=6,j=389, Depth Avg
129  .999896824359894
129.041687011719     .999900698661804
129.08332824707  .999906241893768
129.125015258789     .999907732009888
129.166687011719     .999911069869995
129.20832824707  .999914765357971
129.250030517578     .999916195869446
129.29167175293  .999917268753052
129.333343505859     .999915540218353
129.375030517578     .999913275241852
129.41667175293  .999912321567535
129.458358764648     .999917924404144
129.5    .999931216239929
129.541687011719     .999949038028717
129.58332824707  .999967098236084
129.625015258789     .99997490644455
129.666687011719     .99997478723526
129.70832824707  .999971747398376
129.750030517578     .999971866607666
129.79167175293  .999963641166687
129.833343505859     .999957323074341
129.875030517578     .999943554401398
129.91667175293  .999928772449493
129.958358764648     .999920845031738
 24     i=6,j=368, Depth Avg
129  .999881386756897
129.041687011719     .999881148338318
129.08332824707  .999884247779846
129.125015258789     .999890089035034
129.166687011719     .999891340732574
129.20832824707  .999898195266724
129.250030517578     .999899566173553
129.29167175293  .99989926815033
129.333343505859     .999900281429291
129.375030517578     .999897241592407
129.41667175293  .999898076057434
129.458358764648     .999900460243225
129.5    .999909520149231
129.541687011719     .999929904937744
129.58332824707  .99994695186615
129.625015258789     .999955654144287
129.666687011719     .999966681003571
129.70832824707  .999970495700836
129.750030517578     .999961376190186
129.79167175293  .999959707260132
129.833343505859     .999947667121887
129.875030517578     .999938011169434
129.91667175293  .999923884868622
129.958358764648     .999911487102509
 24     i=6,j=348, Depth Avg
129  .999867141246796
129.041687011719     .99986469745636
129.08332824707  .999867618083954
129.125015258789     .999873995780945
129.166687011719     .999871373176575
129.20832824707  .999880611896515
129.250030517578     .999884486198425
129.29167175293  .999886929988861
129.333343505859     .999884188175201
129.375030517578     .999882280826569
129.41667175293  .999883890151978
129.458358764648     .9998899102211
129.5    .999895036220551
129.541687011719     .999910831451416
129.58332824707  .999934732913971
129.625015258789     .999945521354675
129.666687011719     .999955534934998
129.70832824707  .999961793422699
129.750030517578     .999957978725433
129.79167175293  .999951660633087
129.833343505859     .999941468238831
129.875030517578     .999929845333099
129.91667175293  .999918639659882
129.958358764648     .999907255172729
 24     i=6,j=327, Depth Avg
129  .999853491783142
129.041687011719     .999850451946259
129.08332824707  .999851763248444
129.125015258789     .99985283613205
129.166687011719     .999859154224396
129.20832824707  .999862432479858
129.250030517578     .99987006187439
129.29167175293  .999870896339417
129.333343505859     .999869167804718
129.375030517578     .999869883060455
129.41667175293  .999871730804443
129.458358764648     .999876856803894
129.5    .999881386756897
129.541687011719     .999897122383118
129.58332824707  .999917089939117
129.625015258789     .99993109703064
129.666687011719     .999943196773529
129.70832824707  .999952137470245
129.750030517578     .999950647354126
129.79167175293  .999947309494019
129.833343505859     .999936044216156
129.875030517578     .999920547008514
129.91667175293  .999912142753601
129.958358764648     .999901592731476
 24     i=6,j=292, Depth Avg
129  .999843060970306
129.041687011719     .999837875366211
129.08332824707  .999838352203369
129.125015258789     .999838829040527
129.166687011719     .999844074249268
129.20832824707  .999848902225494
129.250030517578     .999852895736694
129.29167175293  .999858498573303
129.333343505859     .999856173992157
129.375030517578     .99985283613205
129.41667175293  .999858915805817
129.458358764648     .999866425991058
129.5    .999874234199524
129.541687011719     .999885022640228
129.58332824707  .99990314245224
129.625015258789     .999919414520264
129.666687011719     .99993097782135
129.70832824707  .999938011169434
129.750030517578     .999949157238007
129.79167175293  .999946355819702
129.833343505859     .999929904937744
129.875030517578     .999915540218353
129.91667175293  .999905586242676
129.958358764648     .999898970127106
 24     i=6,j=259, Depth Avg
129  .999834001064301
129.041687011719     .999824702739716
129.08332824707  .999821126461029
129.125015258789     .999821424484253
129.166687011719     .99982613325119
129.20832824707  .999833703041077
129.250030517578     .999835669994354
129.29167175293  .999840080738068
129.333343505859     .999838411808014
129.375030517578     .999837756156921
129.41667175293  .99984335899353
129.458358764648     .999850928783417
129.5    .9998619556427
129.541687011719     .999873995780945
129.58332824707  .99988579750061
129.625015258789     .999900877475739
129.666687011719     .999914228916168
129.70832824707  .999925315380096
129.750030517578     .999936759471893
129.79167175293  .999936878681183
129.833343505859     .99992710351944
129.875030517578     .999910295009613
129.91667175293  .999898672103882
129.958358764648     .999892175197601
 24     i=6,j=226, Depth Avg
129  .999824702739716
129.041687011719     .999814808368683
129.08332824707  .999808013439178
129.125015258789     .999804198741913
129.166687011719     .999807476997375
129.20832824707  .999813139438629
129.250030517578     .999822676181793
129.29167175293  .99982351064682
129.333343505859     .999824523925781
129.375030517578     .999823033809662
129.41667175293  .999825477600098
129.458358764648     .999838531017303
129.5    .999848604202271
129.541687011719     .999862551689148
129.58332824707  .999877154827118
129.625015258789     .999886035919189
129.666687011719     .999900817871094
129.70832824707  .999914348125458
129.750030517578     .999924421310425
129.79167175293  .999934256076813
129.833343505859     .999922454357147
129.875030517578     .999904692173004
129.91667175293  .999892711639404
129.958358764648     .999884963035584
 24     i=6,j=192, Depth Avg
129  .99981552362442
129.041687011719     .99980354309082
129.08332824707  .999796211719513
129.125015258789     .999791741371155
129.166687011719     .999789655208588
129.20832824707  .999796688556671
129.250030517578     .999803066253662
129.29167175293  .999805808067322
129.333343505859     .999804735183716
129.375030517578     .999807178974152
129.41667175293  .99980890750885
129.458358764648     .999818205833435
129.5    .99983286857605
129.541687011719     .999846994876862
129.58332824707  .99986344575882
129.625015258789     .999871373176575
129.666687011719     .999883532524109
129.70832824707  .999895215034485
129.750030517578     .999908864498138
129.79167175293  .999918818473816
129.833343505859     .999915540218353
129.875030517578     .999901354312897
129.91667175293  .999885380268097
129.958358764648     .999875426292419
 24     i=6,j=153, Depth Avg
129  .999805927276611
129.041687011719     .999794244766235
129.08332824707  .999784469604492
129.125015258789     .999773502349854
129.166687011719     .999773383140564
129.20832824707  .999773502349854
129.250030517578     .999780893325806
129.29167175293  .999789416790009
129.333343505859     .999786853790283
129.375030517578     .999787390232086
129.41667175293  .999790966510773
129.458358764648     .999798953533173
129.5    .999812364578247
129.541687011719     .999829947948456
129.58332824707  .999845206737518
129.625015258789     .999858379364014
129.666687011719     .999864339828491
129.70832824707  .999876201152802
129.750030517578     .999890923500061
129.79167175293  .999903082847595
129.833343505859     .999906420707703
129.875030517578     .999894261360168
129.91667175293  .999879479408264
129.958358764648     .999869167804718
 24     i=6,j=128, Depth Avg
129  .999789476394653
129.041687011719     .999781906604767
129.08332824707  .999774098396301
129.125015258789     .999761164188385
129.166687011719     .999757647514343
129.20832824707  .999755144119263
129.250030517578     .999756097793579
129.29167175293  .99976259469986
129.333343505859     .999769032001495
129.375030517578     .999765932559967
129.41667175293  .999771893024445
129.458358764648     .999777555465698
129.5    .99978905916214
129.541687011719     .999803423881531
129.58332824707  .999822616577148
129.625015258789     .999835848808289
129.666687011719     .999845564365387
129.70832824707  .999853193759918
129.750030517578     .999869644641876
129.79167175293  .999880850315094
129.833343505859     .999887049198151
129.875030517578     .999883890151978
129.91667175293  .999871850013733
129.958358764648     .999860405921936
 24     i=6,j=110, Depth Avg
129  .999779164791107
129.041687011719     .999770522117615
129.08332824707  .999760329723358
129.125015258789     .99975997209549
129.166687011719     .999742865562439
129.20832824707  .999745786190033
129.250030517578     .999750256538391
129.29167175293  .999748349189758
129.333343505859     .999751448631287
129.375030517578     .999754190444946
129.41667175293  .999757528305054
129.458358764648     .999769866466522
129.5    .999785482883453
129.541687011719     .999794661998749
129.58332824707  .999817728996277
129.625015258789     .999830901622772
129.666687011719     .999835133552551
129.70832824707  .999845504760742
129.750030517578     .999861538410187
129.79167175293  .999873220920563
129.833343505859     .999875068664551
129.875030517578     .999870419502258
129.91667175293  .99986457824707
129.958358764648     .999849319458008
 24     i=6,j=93, Depth Avg
129  .999766826629639
129.041687011719     .999762296676636
129.08332824707  .999753355979919
129.125015258789     .999748826026917
129.166687011719     .999739050865173
129.20832824707  .999720871448517
129.250030517578     .999734222888947
129.29167175293  .999731242656708
129.333343505859     .999733805656433
129.375030517578     .999738991260529
129.41667175293  .999740064144135
129.458358764648     .999753355979919
129.5    .999762356281281
129.541687011719     .999780237674713
129.58332824707  .999796271324158
129.625015258789     .999814510345459
129.666687011719     .999817430973053
129.70832824707  .99983161687851
129.750030517578     .999845683574677
129.79167175293  .999861538410187
129.833343505859     .999863564968109
129.875030517578     .999863147735596
129.91667175293  .999865055084229
129.958358764648     .999856472015381
 24     i=6,j=76, Depth Avg
129  .999753832817078
129.041687011719     .999746739864349
129.08332824707  .999741792678833
129.125015258789     .999738156795502
129.166687011719     .999724328517914
129.20832824707  .999722361564636
129.250030517578     .999713897705078
129.29167175293  .999720215797424
129.333343505859     .999716877937317
129.375030517578     .999717235565186
129.41667175293  .999724268913269
129.458358764648     .999728620052338
129.5    .999743044376373
129.541687011719     .999756336212158
129.58332824707  .999765694141388
129.625015258789     .999791264533997
129.666687011719     .999801218509674
129.70832824707  .999810576438904
129.750030517578     .999826610088348
129.79167175293  .999833583831787
129.833343505859     .999842703342438
129.875030517578     .999847292900085
129.91667175293  .999846518039703
129.958358764648     .999843716621399
 24     i=6,j=57, Depth Avg
129  .999737977981567
129.041687011719     .999729692935944
129.08332824707  .999728322029114
129.125015258789     .999724566936493
129.166687011719     .99971330165863
129.20832824707  .999713182449341
129.250030517578     .999702155590057
129.29167175293  .999702036380768
129.333343505859     .999697923660278
129.375030517578     .999699771404266
129.41667175293  .999703884124756
129.458358764648     .999720335006714
129.5    .999739944934845
129.541687011719     .999764323234558
129.58332824707  .999775350093842
129.625015258789     .999794840812683
129.666687011719     .999800264835358
129.70832824707  .99980890750885
129.750030517578     .999824464321136
129.79167175293  .99983423948288
129.833343505859     .999840199947357
129.875030517578     .999831259250641
129.91667175293  .999834179878235
129.958358764648     .999835610389709
 24     i=6,j=39, Depth Avg
129  .999715983867645
129.041687011719     .999719083309174
129.08332824707  .999716222286224
129.125015258789     .999715089797974
129.166687011719     .999704778194427
129.20832824707  .999699890613556
129.250030517578     .999691367149353
129.29167175293  .999691903591156
129.333343505859     .999683082103729
129.375030517578     .999683618545532
129.41667175293  .999683201313019
129.458358764648     .99969744682312
129.5    .999726533889771
129.541687011719     .999751925468445
129.58332824707  .999759078025818
129.625015258789     .99978768825531
129.666687011719     .999797701835632
129.70832824707  .999793410301209
129.750030517578     .999819159507751
129.79167175293  .999822616577148
129.833343505859     .999823331832886
129.875030517578     .999825894832611
129.91667175293  .999815165996552
129.958358764648     .999819099903107
 24     i=6,j=21, Depth Avg
129  .999696910381317
129.041687011719     .999701023101807
129.08332824707  .999699056148529
129.125015258789     .999692380428314
129.166687011719     .999688744544983
129.20832824707  .999685347080231
129.250030517578     .999680936336517
129.29167175293  .99967360496521
129.333343505859     .999662935733795
129.375030517578     .999661505222321
129.41667175293  .99966698884964
129.458358764648     .999664664268494
129.5    .99968409538269
129.541687011719     .999708712100983
129.58332824707  .999718606472015
129.625015258789     .999738812446594
129.666687011719     .999759376049042
129.70832824707  .999764382839203
129.750030517578     .999777615070343
129.79167175293  .999795854091644
129.833343505859     .999795794487
129.875030517578     .999796092510223
129.91667175293  .999798774719238
129.958358764648     .999801099300385
 24     i=6,j=4, Depth Avg
129  .999682068824768
129.041687011719     .999686241149902
129.08332824707  .999697148799896
129.125015258789     .999681234359741
129.166687011719     .999677836894989
129.20832824707  .999678015708923
129.250030517578     .999674320220947
129.29167175293  .999665796756744
129.333343505859     .999662160873413
129.375030517578     .99965512752533
129.41667175293  .999659299850464
129.458358764648     .999676048755646
129.5    .999703407287598
129.541687011719     .999747574329376
129.58332824707  .999796569347382
129.625015258789     .999792635440826
129.666687011719     .999805927276611
129.70832824707  .999807775020599
129.750030517578     .999792218208313
129.79167175293  .999798476696014
129.833343505859     .99979567527771
129.875030517578     .999777317047119
129.91667175293  .999795794487
129.958358764648     .99979555606842

数据集是 24 个位置的染料浓度时间序列。每个站有 24 个数据点(每小时)。因此,在数据的第一行中,24 表示该站点的数据点数,表示该站点的数据点,i=5,j=529, Depth Avg并且id数据是深度平均的。为简单起见,我们可以将第一个位置视为 1,将最后一个位置视为 24。我想绘制图表,以便将每个站点的时间序列绘制为箱线图,并绘制另一条线/曲线,将所有的中点连接起来数据。24 个点的位置定义为 dist <- c(0,1850,seq(from=3100,to=29350,by=1250))。这意味着起点在0,第二点在1850米,所有其他站点相距1250m。

预期情节:

距离与染料浓度的关系(显示每个位置的箱线图和连接每个站点 24 个数据点的中值的曲线)。

4

3 回答 3

4
> datLines <- readLines(textConnection(" 24     i=6,j=529, Depth Avg
+ 129  1
+ 129.041687011719     1.00000035762787
+ 129.08332824707  .99999988079071
+ 129.125015258789     1.00000011920929
.......
###### snipped many lines
+ 129.833343505859     .99979567527771
+ 129.875030517578     .999777317047119
+ 129.91667175293  .999795794487
+ 129.958358764648     .99979555606842"))

grp <- cumsum(grepl("Depth", datLines)) # cumsum 1/0's creates group var
rdLines <- lapply( split(datLines, grp), # read within each group
                   function(x) read.table(text=x, skip=1) )
str(rdLines[1])
dafrm <- do.call(rbind, rdLines)  # bind in one dataframe
dafrm$grp <- rep(1:24, each=24)   # label them
bpt <- boxplot(V2~grp, data=dafrm) # save values in 'bpt' variable
str(bpt)
lines(1:24, bpt$stats[ 3, ])  # values of medians as y-arg to `lines`

在此处输入图像描述

于 2013-09-03T23:34:53.260 回答
1

ggplot这是一个您可以适应的简单示例。

set.seed(1)
df1 <- data.frame(loc=rep(seq(1:3),each=5),
                  conc=rnorm(15))
library(ggplot2)
gg<-ggplot(df1,aes(factor(loc),conc))
gg +
geom_boxplot((aes(fill = factor(loc)))) +
geom_jitter() +
stat_summary(fun.y=median, geom="smooth", aes(group=1))

给予:

在此处输入图像描述

(感谢@Bernd Weiss

于 2013-09-03T21:35:54.160 回答
0

如果我理解正确并且您想要的是获取时间序列的摘要,制作每个位置的浓度箱线图,就可以了。在此处输入图像描述

ggplot(df, aes(x = loc, y = Concentration, group = x)) + geom_boxplot() +     stat_summary(fun.y=median, geom="line")
于 2015-10-21T11:11:02.077 回答