使用R在3D中绘制多个系列

时间:2019-03-05 15:25:26

标签: r plot 3d

我在Mathematica SE上读过this post,内容涉及在3D图表中绘制多个序列。有什么办法可以使用R做类似的事情吗? enter image description here

我有4个系列,基本上是使用不同方法得出的近似值,我想在3D图中比较它们,而不是在2D图中将它们全部绘制在一起。

谢谢。

编辑:根据评论中的建议,我保留了数据。

structure(c(0.264726326720194, 0.0519945752635645, 0.0357518544181836, 
-0.00876964213296186, -0.025388867534768, -0.0333315539468369, 
-0.0315538601785337, -0.0146064345813073, -0.00516299202900693, 
0.00918874199406888, 0.0109349495933589, 0.0142210240269636, 
0.014928866620631, 0.0336364614998731, 0.0767601482815889, 0.0702435151903681, 
0.0427526162723857, 0.000903485484597233, -0.0344112254620015, 
-0.0632590460485075, -0.163237038236638, -0.0691545012949969, 
0.209888795597967, 2.80583818936139, 3.76147674605186, -0.0812260382056143, 
4.80919773334928, 0.538580841526193, 0.511042076791523, 0.510773156833391, 
0.868246972910268, 1.32582825635557, 1.87731078880249, 2.86764680517487, 
2.05592396024291, 1.18273931925319, 0.150062563945235, 0.0895007161677267, 
0.0541334209516807, 0.0507310469087633, 0.274438839289304, 0.47915977085874, 
0.482484636738185, 0.37932968901925, 0.3478120952377, 0.352408006614401, 
1.22067281965959, 1.30630304174988, 1.61571165280014, 2.69893656878862, 
3.4468659625133, 3.92963931205015, 4.4805992363346, 4.53124502882446, 
5.42393215431838, 3.47378440738958, 3.28388786989187, 2.3795186498099, 
2.29054781187137, 1.88732989131975, 1.19138246224371, 0.520628282552336, 
0.34539905005095, 0.0692723851598036, 0.0409565714033323, 0.00598498570922801, 
0.00385567287700128, -0.00571853965645444, -0.0717850537143094, 
-0.0813970230043355, -0.0826889049081263, -0.0823649183272997, 
-0.0304736282070258, 0.122539775132105, 0.160279856848011, 0.193112797691106, 
0.723285661315604, 0.868004392335873, 1.44986480599027, 2.40045080164269, 
3.59041849209622, 3.59679472037708, 3.95650676962359, 4.01193979039516, 
4.08971558904855, 4.09152361643571, 4.06721800875475, 4.03067443539435, 
3.94670011133615, 3.89611253208119, 3.490294677216, 3.09867811410813, 
2.74656410721782, 1.20341774423748, 0.918339112522217, 0.793959688146885, 
0.451914404862965, 0.446107765636017, 0.343545446880067, 0.284849358959678, 
0.262230109192467, 0.19013643332333, 0.169931418315258, 0.125163999238577, 
0.113620536215228, 0.0934399642097052, 0.071923596764825, 0.0570776989504294, 
0.0424355359012944, 0.0336540256870939, 0.00469950213718898, 
0.00390389984177886, 0.00641150775114219, 0.0108317583624266, 
0.0141502484549949, 0.0145633268868783, 0.0221372492651964, 0.0235564281736623, 
0.0269398829784271, 0.0285099947725436, 0.0356796537381491, 0.0628826548408634, 
0.0691459960976604, 0.0786659577589584, 0.0893045996204827, 0.10317917441204, 
0.128819284656152, 0.131162494732263, 0.133111913626718, 0.134257394365466, 
3.39550424548239, 4.23368330894007, 4.07212796150909, 3.40249523290743, 
-0.0230225133534669, -0.0343698483623807, 0.00928896058901185, 
0.0456507050414939, 0.106420638844949, 0.112440406556023, 0.139279001218171, 
0.135483202031525, 0.12553435583047, -0.002238793584938, -0.0222925700165109, 
-0.214737784886411, -0.219925357039059, -0.236292861110261, -0.234014660677215, 
-0.0618075551171148, -0.0586244184040394, 0.0485929935072, 0.874855144211639, 
2.12760328603323, 2.31170943358288, 1.82167729702947, 1.5771463252354, 
1.4960388345759, 5.0030238190131, 5.11134017935042, 2.2811866598861, 
1.44661632639074, 1.08883406987073, 1.04705861931402, 0.48878837976501, 
1.07304686581643, 4.24697846382898, 3.71779252573722, 0.0432335120960201, 
0.029521636072827, 0.0236345096028152, 0.016603859716668, 0.000707969720220747, 
-0.00663028802633298, -0.00818862904777039, -0.0187956378106497, 
-0.0192826279565686, -0.0249468794302525, -0.0298743817414437, 
-0.0375404524989146, -0.0386107340179226, -0.0397807148654252, 
-0.0398522385369815, -0.0424340109526828, -0.0429153257350097, 
-0.0447035452808101, -0.0451861377165556, -0.0453114244099815, 
-0.0431803103941926, -0.0294460069231977, -0.0288821133905922, 
-0.0237271236701295, -0.0216530241953208, -0.0179056690672022, 
-0.0153396134567517, -0.0147024035118559, 0.0184461124499898, 
0.0633977862229277, 0.0960103292935189, 0.154531382068891, 0.166222220965189, 
0.311775208058672, 0.0262122944402187, 0.00406904216133547, -0.0531271403198575, 
-0.0678950637992328, -0.0503156864506777, -0.0325673784991755, 
0.0274984852064646, 0.0420366076302473, 0.0549125446065543, 0.0559054112739682, 
0.0574776421507823, 0.0577669170993994, 0.0593343349759949, -0.0590552238513658, 
-0.0777173882966924, -0.0862244802805386, -0.0696989155580985, 
-0.0489309670536278, -0.0300375655969861, 0.0409711861493152, 
0.77226662637262, 0.844559484224505, 1.44248537851497, 1.92907051995605, 
2.41455610680645, 1.87468477739996, 1.60403833864894, 1.58738740097644, 
1.58097224752864, 1.51386108104099, 1.47897209231966, 1.44853359227433, 
1.3882383377636, 1.29106015750535, 1.19341214668228, 0.722335520233655, 
0.597025619816809, 0.440672463231994, 0.3635568683127, -0.120932201552045, 
-0.281305792647869, -0.236857769723249, 0.152159062651098, 0.32246868055164, 
0.62379572710563, 1.90297567903255, 1.97450684867492, 2.21156759641417, 
2.87577306990975, 3.26649284737365, 3.53519086403934, 4.3692906513733, 
4.45373584013415, 3.82886153306675, 3.0132727139255, 2.9377103098081, 
2.55483035494994, 2.51409205321706, 2.31882377596158, 1.91632415912898, 
1.30097274144291, 0.986739214820165, -0.840031469695679, -0.598364262509354, 
-0.171899545581517, -0.14861919858167, -0.0484789439388282, 0.3887829957088, 
0.346085799061236, 0.30867357626934, 0.227136258279786, -0.121969373015476, 
-0.162264557296276, -0.139768071708659, -0.115775243199466, 0.696677394972273, 
0.981396948108963, 1.92287452637551, 2.64550010074054, 3.43335241503525, 
3.4386383217432, 3.79603678995955, 3.87337538560924, 4.05532564979387, 
4.07479661422677, 4.19903328041159, 4.16149420272591, 4.04146744042987, 
3.96680575855573, 3.40392660674673, 2.92658242585187, 2.53344802295093, 
1.36779284423732, 1.17779750810197, 1.0735309259656, 0.31131205558901, 
0.295382348170772, 0.0977402176234139, 0.0794444565092776, 0.0981169258499777, 
0.208508954158652, 0.226503478733009, 0.228485094101272, 0.217429892741513, 
0.181763149590917, 0.120307865195582, 0.0800305304212209, 0.0465649388011041, 
0.0314052285975851, 0.0497611768462346, 0.0479154871956927, 0.0328198288591149, 
0.0165837464355739, 0.015631340174319, 0.0159573399414306, 0.033392846887959, 
0.0385204967455977, 0.0525507022806872, 0.0598415274556997, 0.0985234481807557, 
0.174945832137119, 0.135408682037904, 0.0354394360547859, -0.131543075555819, 
-0.427147588086275, -0.00524296412304892, 0.129737868986585, 
0.25636400023215, 0.33707916769454, 4.31152914902484, 4.07831541883163, 
3.62514413456621, 2.86509544501792, 0.37232254109593, 0.148668479024813, 
0.0847410856272778, 0.054462387258687, 0.0610573980871095, 0.0637192491926133, 
0.076933186279013, 0.0762446695632449, 0.0718009488360127, -0.00916230845338778, 
-0.025242366342438, -0.189070485119321, -0.194809067590197, -0.216497146034024, 
-0.274561040309146, -0.15179744442356, -0.14747155338017, 0.0082352084290806, 
0.855570772046996, 1.83680373448303, 2.53282994516884, 2.65404272510773, 
2.68965199521135, 2.70374210534305, 2.29943234822307, 2.10423348443966, 
1.83713637519009, 1.833188964444, 1.84590171091468, 1.84827119081348, 
1.91458862448559, 2.49108488474197, 3.14010630628568, 3.21454203172196, 
0.46816684886658, 0.131277884578033, 0.0201564437815914, -0.0804337531880335, 
-0.156326337593453, -0.157659757179059, -0.156939032166368, -0.139636219192007, 
-0.138203986305946, -0.115925169954069, -0.0855562684814691, 
-0.0039574513305799, 0.00991012162255364, 0.0247136019991218, 
0.0256040118830456, 0.0560637386590778, 0.0612046191595866, 0.0767713568841026, 
0.0786827100918888, 0.0470257866446126, -0.000181706064207268, 
-0.0648168021185214, -0.0653704689700948, -0.067170782675105, 
-0.0668258665664111, -0.0652583195624373, -0.0635801737737061, 
-0.0630954277989104, -0.0128736895012229, 0.0850628697745825, 
0.156883880676665, 0.164102724200354, 0.147088644556542, 0.31813487215183, 
0.0207954804668227, -0.00250043644078296, -0.0634421475797118, 
-0.0801901087462027, -0.0648769080180999, -0.047624448022854, 
0.0342961645409183, 0.0580852746188894, 0.0807923114800402, 0.0827295621131705, 
0.085953848758776, 0.0865783632016111, 0.094589284396441, -0.0595420959295613, 
-0.114596845497791, -0.164354222543242, -0.154608215708972, -0.125432739152536, 
-0.0952814559972583, 0.0293107536588939, 1.0546058600976, 1.11612754927836, 
1.50523186814777, 1.73400529333438, 2.01945116680579, 2.00184052878916, 
1.74466157537989, 1.72364701478215, 1.71530484929916, 1.6173665357356, 
1.55511970448672, 1.48928219107421, 1.30713395112903, 1.11817091810725, 
0.985274645510401, 0.550092898433029, 0.458607844130327, 0.343878140286906, 
0.282274718621465, -0.22375556609193, -0.108417944651074, -0.00402126863107632, 
0.494258808917176, 0.673404183613101, 0.971654483015523, 1.96245632073384, 
2.00772953501663, 2.15287812118462, 2.5617565566131, 2.84016880090945, 
3.0573347815908, 4.06624778576371, 4.26623421506321, 4.63241848899378, 
3.50309207963438, 3.38329830770628, 2.75073566361576, 2.68122857488927, 
2.34300787422959, 1.62638680750259, 0.695499173013121, 0.312824686903319, 
-1.02678584672006, -0.555796308865828, -0.0705913556998031, -0.0451341951626185, 
0.0635934448194765, 0.477036120893802, 0.384817855431004, 0.325320554765846, 
0.209378051556736, -0.179616719573513, -0.200782557532109, -0.169464864493686, 
-0.137278312088967, 0.702578452396325, 0.975999559603518, 1.86327153599155, 
2.63564122181742, 3.48246832102968, 3.48803591854038, 3.85664448811322, 
3.93292644088504, 4.08678488485315, 4.09625136449674, 4.10858072669484, 
4.04748287885947, 3.93688862937521, 3.8815117284114, 3.4742571048703, 
3.07937673767245, 2.73889649630738, 1.36699142383618, 1.1055721001065, 
0.96694998190186, 0.167786720632993, 0.160155007581824, 0.193746277865569, 
0.233156919558028, 0.240983221335769, 0.226788080779136, 0.208214488523485, 
0.145143418513132, 0.130656121686313, 0.109954027077891, 0.0969977672890203, 
0.0964226338547069, 0.106638677183081, 0.120866800481218, 0.0708568973232289, 
0.00695062036309466, -0.0606871318893136, -0.0544564725663046, 
-0.0283845359498546, -0.0243932534216069, 0.0686354197916168, 
0.089376049145922, 0.142148434109628, 0.168097014147443, 0.285392174302443, 
0.221699885068286, 0.112551369182174, -0.111772326427067, -0.444359801686557, 
-0.715639159365316, 0.112213495253149, 0.286425828545953, 0.446105582192352, 
0.546433884960904, 4.28576476670782, 3.98155928131696, 3.50681509674653, 
2.76273089667536, 0.441134504684503, 0.208001472585187, 0.132692979849785, 
0.0887474494147578, 0.0663701580726508, 0.0688597675596422, 0.0789742727240471, 
0.0743385506425541, 0.0667909019315664, -0.041435636969173, -0.0619068966717932, 
-0.254169165743238, -0.255987185529187, -0.257382049899167, -0.20186728116477, 
0.0120060505422932, 0.0155821652847443, 0.136625667392821, 0.718389409892065, 
1.37473930395657, 2.21081170534535, 2.45312272189842, 2.55255233432476, 
2.76004727894345, 2.84602877956959, 2.76780531232154, 2.29292272075718, 
2.11633070798678, 2.03755658483202, 2.02812490060462, 1.89120432437774, 
1.7639067250144, 2.11566114317689, 2.46726595455569, 1.64799124451436, 
0.827349878050207, 0.504384988524458, 0.156148586325349, -0.436183048752028, 
-0.585218174735833, -0.603463879756167, -0.561847385359541, -0.551396642362403, 
-0.358880892439318, -0.160850102575157, 0.103639729995332, 0.132955605147317, 
0.16130890920929, 0.16289296509337, 0.203226642179218, 0.205449923791694, 
0.179784642352026, 0.151193373373486, -0.045582323616085, -0.127186385863469, 
-0.0990098207211484, -0.0949809039677722, -0.0647752930609607, 
-0.0554114274276175, -0.0417005423988704, -0.0343565359559932, 
-0.0327619854568398, -0.0267510001728121, 0.0556217887729598, 
0.174263684074273, 0.171997502085958, 0.140758459045819, 0.297444749061429, 
0.0402099310297527, 0.0100727876984427, -0.0757404911774042, 
-0.0929566898627459, -0.0312927378648481, 0.00771818351251174, 
0.116006391457665, 0.106609276813698, 0.035598604660075, 0.0267307972450576, 
0.0115146889063764, 0.0084708688238112, -0.0484037446028178, 
-0.0219918248487375, -0.0159675872227402, 0.0043729553919568, 
0.0326012585443539, 0.000281510678447325, -0.0620435369925966, 
-0.26272102105821, 0.76083254505355, 0.854311055966522, 1.43242928994859, 
1.84501522853675, 2.61563234349947, 2.60763244814317, 1.29450277504279, 
1.22485501106195, 1.20040659476855, 1.10725424801266, 1.27683301176271, 
1.54239605646298, 2.00954516576359, 1.95046888583571, 1.59082261771774, 
0.162614483988259, 0.0780290251066953, 0.0692467302421387, 0.0806772272103959, 
0.302769364068514, 0.423030753711247, 0.401415828483137, 0.300928442592403, 
0.319958430295106, 0.426634650389951, 1.46565706660695, 1.54283582620254, 
1.80729630041456, 2.6294460441048, 3.16366566221933, 3.51715258121692, 
4.60772860924487, 4.77315610939386, 4.90088894614475, 3.41062916320435, 
3.25938242261605, 2.49739371527411, 2.4181760856661, 2.04791516927767, 
1.36161451256267, 0.571322609385286, 0.275792704049577, -0.17449235727053, 
-0.0393358374447876, 0.0236194826956478, 0.024956235788116, 0.029256936522208, 
0.00405468971574087, -0.00127457002862309, -0.00504907157451204, 
-0.0158343394478402, -0.0643821410794774, 0.0684930962638366, 
0.101980289267886, 0.129225370528713, 0.684775657722086, 0.902971263828594, 
1.65812339760285, 2.34958879951803, 3.39395297708664, 3.40240208385398, 
3.99667518542078, 4.10882275398402, 4.26148285668492, 4.25937534051223, 
4.02112290683456, 3.96676563115412, 3.89768581394737, 3.82907594913168, 
3.35604638797365, 3.09964550976276, 2.83967500002766, 1.40724440969181, 
1.1211542695938, 0.971118803281461, 0.166687693367237, 0.159652476630053, 
0.162069834769526, 0.208685373451086, 0.22547443477539, 0.243190929530863, 
0.227850546929926, 0.16199742320586, 0.142210613739426, 0.112716819453779, 
0.0981896257753585, 0.0962997073479804, 0.0944937492681752, 0.0909642278411175, 
0.0105043713060817, -0.0197757270934398, -0.0323788859053742, 
0.0655334884819141, 0.165470598084682, 0.17333546667349, 0.12132772567055, 
0.0881733663779588, 0.00189193257058876, -0.0343767896918982, 
-0.131023311501517, -0.0166978762149107, 0.0328843114506318, 
0.0677540797724365, 0.0163998222671331, -0.104610784831145, 0.0530175853731326, 
0.127909957356856, 0.20273289436507, 0.253138830517605, 3.84282681875765, 
3.9891245629393, 3.77776520618879, 3.29343058306748, 0.375585703304909, 
0.0779957910567183, 0.0407419143437123, 0.0378608766352551, 0.0287907549270511, 
0.029272695017989, 0.0686863275635389, 0.103112961511728, 0.112948410970949, 
0.017045859137018, -0.00632885479324888, -0.259797845486401, 
-0.266490748146874, -0.281192179454365, -0.172345479326018, -0.00902246723849643, 
-0.00911023290901703, 0.0139280471605817, 1.0703353625081, 1.82957062254371, 
1.78770033295884, 1.88181033133765, 2.00412589984894, 2.6037530651406, 
4.12212607677221, 4.11105858846819, 2.27563035896141, 1.62111176434414, 
1.34306180856625, 1.31183866660554, 0.945599024375701, 1.50871773773923, 
3.25325389783422, 3.90132093275661, 0.531570684214859, 0.0432223293714559, 
-0.0452905305689294, -0.0754386746103556, -0.0559419479971322, 
-0.0535355848812685, -0.0574941300807028, -0.138569533939846, 
-0.144501420191483, -0.206808304721634, -0.197883843167317, -0.0521116794037184, 
-0.0257896925944655, 0.00180202083131774, 0.0034192112406884, 
0.0620968305457247, 0.0759305177022307, 0.133595983383066, 0.141440152238344, 
0.0606296858003502, -0.021243195975888, -0.0967296289742292, 
-0.0938682917860364, -0.0549467959269143, -0.0356438128225521, 
-0.0245117538204165, -0.0458200355208959, -0.0523429516563995, 
-0.096924008705308, 0.0975755166819738, 0.18314250378897, 0.165601314393162, 
0.137249751930264), .Dim = c(201L, 4L), .Dimnames = list(c("1", 
"2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", 
"14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", 
"25", "26", "27", "28", "29", "30", "31", "32", "33", "34", "35", 
"36", "37", "38", "39", "40", "41", "42", "43", "44", "45", "46", 
"47", "48", "49", "50", "51", "52", "53", "54", "55", "56", "57", 
"58", "59", "60", "61", "62", "63", "64", "65", "66", "67", "68", 
"69", "70", "71", "72", "73", "74", "75", "76", "77", "78", "79", 
"80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "90", 
"91", "92", "93", "94", "95", "96", "97", "98", "99", "100", 
"101", "102", "103", "104", "105", "106", "107", "108", "109", 
"110", "111", "112", "113", "114", "115", "116", "117", "118", 
"119", "120", "121", "122", "123", "124", "125", "126", "127", 
"128", "129", "130", "131", "132", "133", "134", "135", "136", 
"137", "138", "139", "140", "141", "142", "143", "144", "145", 
"146", "147", "148", "149", "150", "151", "152", "153", "154", 
"155", "156", "157", "158", "159", "160", "161", "162", "163", 
"164", "165", "166", "167", "168", "169", "170", "171", "172", 
"173", "174", "175", "176", "177", "178", "179", "180", "181", 
"182", "183", "184", "185", "186", "187", "188", "189", "190", 
"191", "192", "193", "194", "195", "196", "197", "198", "199", 
"200", "201"), NULL))

1 个答案:

答案 0 :(得分:1)

您可以使用plotlyplot3d(来自rgl)来完成它。

library(data.table)
library(plotly)
data <- data.table(data)
data[,x := .I]
data <- melt(data, id.vars = "x")

plot_ly(data, x = ~x, y = ~variable, z = ~value, type = 'scatter3d', mode = 'lines', color = ~variable)

enter image description here

library(rgl)
plot3d(data$x, data$variable, data$value, col = rainbow(1000), type = "l")