Stratigraphic plot of geochemical data using ggplot2 and tidypaleo - r

I am trying to create a stratigraphic plot of geochemical element data which should be possible using package tidypaleo.
I want multiple plots of the different element data with Depth (cm) downcore set as the y axis. The data look as follows.
Image of data
I am using this code:
ggplot(wapITRAX, aes(x =BrTi , y = wapITRAX$Depth))+
labs(y = "Depth (cm)")+
geom_lineh()+
theme_classic()+
scale_y_reverse()
However, this only plots one element and I am trying to achieve a plot like this Image of plot
> dput(head(wapITRAX))
structure(list(Depth = 0:5, IncCoh = c(6.049230907, 5.975282432,
5.736199822, 5.658584418, 5.659008377, 5.597103404), BrTi =
c(50.50197628,
22.09236453, 23.48370927, 18.62638581, 14.36924414, 17.48777896
), AlIncCOh = c(16.69633736, 8.200449193, 23.70907643, 20.32310407,
28.62692352, 26.44224866), BrCl = c(8.04090623, 4.306048968,
3.417836951, 3.156895904, 2.787628518, 2.059316731), FeTi =
c(332.715415,
235.9371921, 372.726817, 390.7871397, 396.986099, 495.2624867
), CaTi = c(4.071146245, 3.27955665, 4.395989975, 3.677383592,
3.028670721, 4.523910733), ZrRb = structure(c(363L, 447L, 407L,
395L, 450L, 410L), .Label = c("#DIV/0!", "0.447638604",
"0.478169284",
"0.54554134", "0.548501778", "0.561420163", "0.579454254",
"0.579498861",
"0.580801291", "0.589758019", "0.590194076", "0.590277778",
"0.591357754",
"0.592870544", "0.593851133", "0.598519653", "0.599931082",
"0.600979737",
"0.601426307", "0.611710677", "0.617065868", "0.618499405",
"0.621310093",
"0.627720871", "0.63775246", "0.64005168", "0.643958869",
"0.644371941",
"0.645605974", "0.645661658", "0.646672915", "0.647348952",
"0.651578947",
"0.652401176", "0.656186383", "0.657906264", "0.658835905",
"0.662074554",
"0.662361624", "0.669589393", "0.67103429", "0.671371769",
"0.674335863",
"0.674781688", "0.676097561", "0.676639083", "0.677849462",
"0.680497925",
"0.680610514", "0.680725971", "0.683906537", "0.68855859",
"0.689067202",
"0.692353115", "0.692732291", "0.695411392", "0.696067091",
"0.696794872",
"0.699376436", "0.701762744", "0.702015197", "0.702432938",
"0.70361991",
"0.705235754", "0.705426357", "0.708084164", "0.708258528",
"0.708925221",
"0.715226656", "0.715263314", "0.717828827", "0.718975706",
"0.719799305",
"0.720363636", "0.72476489", "0.725426857", "0.725461098",
"0.726030739",
"0.7267645", "0.726998188", "0.727170554", "0.727533265",
"0.730362368",
"0.731182796", "0.735042735", "0.735849057", "0.736184046",
"0.737214792",
"0.738692342", "0.742223591", "0.742639327", "0.742714724",
"0.744126167",
"0.745790081", "0.746207701", "0.746606335", "0.747041077",
"0.749019608",
"0.751204307", "0.751326495", "0.752443737", "0.752994012",
"0.753398969",
"0.754587869", "0.755151515", "0.755466053", "0.756316411",
"0.757107679",
"0.759175941", "0.76070965", "0.761635833", "0.763760166",
"0.763861189",
"0.764076577", "0.765001936", "0.765509391", "0.765795207",
"0.76598579",
"0.767080745", "0.767225748", "0.767262192", "0.770291777",
"0.771194699",
"0.772540984", "0.774533358", "0.77486376", "0.777252364",
"0.778319123",
"0.778445883", "0.779076739", "0.779310345", "0.782186577",
"0.78238342",
"0.782541093", "0.785497178", "0.787594824", "0.788230584",
"0.788916736",
"0.789033068", "0.789052737", "0.789177605", "0.789596048",
"0.790439133",
"0.791078234", "0.792993631", "0.794899978", "0.795265235",
"0.795432921",
"0.798130469", "0.79861957", "0.798894446", "0.799410029",
"0.799679487",
"0.800096223", "0.800119868", "0.800280899", "0.800947004",
"0.80293448",
"0.804118993", "0.804120112", "0.805092452", "0.806161301",
"0.81631016",
"0.816337149", "0.81638756", "0.81827622", "0.818899466",
"0.81993865",
"0.821925431", "0.825329202", "0.825608077", "0.826135414",
"0.826325411",
"0.827108292", "0.829798658", "0.832460733", "0.832814584",
"0.833845295",
"0.833908046", "0.833980583", "0.83741705", "0.837604457",
"0.838292367",
"0.838860231", "0.839741935", "0.846485664", "0.846740374",
"0.84679304
1",
"0.84734599", "0.850027518", "0.850077882", "0.854863613",
"0.85565883",
"0.85591192", "0.857095047", "0.858967536", "0.85897779",
"0.859192457",
"0.859239235", "0.860408412", "0.860505166", "0.8609918",
"0.862821134",
"0.867779204", "0.872207328", "0.872918493", "0.873888706",
"0.874140666",
"0.877452229", "0.879856851", "0.88003663", "0.880155093",
"0.881013197",
"0.882190156", "0.882319978", "0.883029342", "0.883316008",
"0.884908053",
"0.885431692", "0.885849846", "0.889082969", "0.89763062",
"0.898384089",
"0.898527865", "0.9", "0.900719424", "0.904636261", "0.904913848",
"0.905223479", "0.908485273", "0.911212059", "0.916470588",
"0.917162698",
"0.917470525", "0.917952884", "0.918054256", "0.918781726",
"0.922268448",
"0.925987182", "0.926287744", "0.933958724", "0.939701616",
"0.940987438",
"0.941196465", "0.943041526", "0.946832078", "0.947419907",
"0.948080043",
"0.949085366", "0.950099404", "0.950502912", "0.950704225",
"0.953596288",
"0.954868709", "0.95505992", "0.955361596", "0.956422018",
"0.95671509",
"0.959064327", "0.96165309", "0.964232489", "0.965528048",
"0.965874467",
"0.968717195", "0.970270821", "0.971573209", "0.973415133",
"0.974608081",
"0.974986972", "0.978223496", "0.97935022", "0.980142566",
"0.981730052",
"0.982819606", "0.987483236", "0.989587207", "0.991002571",
"0.991932655",
"0.995306859", "0.997555012", "1.001706485", "1.002357873",
"1.005146199",
"1.010493827", "1.011544012", "1.013038906", "1.013469577",
"1.015357613",
"1.01541976", "1.015544041", "1.015937059", "1.016162826",
"1.019393939",
"1.019529957", "1.019994873", "1.028932491", "1.029518072",
"1.030101225",
"1.032310705", "1.03344968", "1.036769138", "1.037322515",
"1.041150092",
"1.041459782", "1.041961577", "1.042347697", "1.047411444",
"1.048390581",
"1.057811121", "1.060218978", "1.065395654", "1.06921167",
"1.071509648",
"1.073730469", "1.076014602", "1.077266637", "1.079983072",
"1.083003953",
"1.086196504", "1.086445657", "1.0867266", "1.0905", "1.092152628",
"1.094730942", "1.095692666", "1.1074142", "1.109534807",
"1.111154446",
"1.111188325", "1.113985094", "1.114045618", "1.128810226",
"1.129375525",
"1.132705479", "1.154833837", "1.155201819", "1.158940397",
"1.161348047",
"1.162953533", "1.175788329", "1.178036097", "1.179280397",
"1.18116463",
"1.198506534", "1.203134068", "1.207592892", "1.208610568",
"1.212525667",
"1.212841855", "1.214403157", "1.216756112", "1.228462377",
"1.23305986",
"1.241758242", "1.258212878", "1.265571914", "1.265707797",
"1.272666444",
"1.279325988", "1.289559543", "1.291191103", "1.296541003",
"1.305111821",
"1.315201411", "1.342263532", "1.344827586", "1.347944377",
"1.352831595",
"1.377717391", "1.37771934", "1.385440181", "1.403358682",
"1.411889597",
"1.412269549", "1.412544902", "1.433843384", "1.444088526",
"1.473706353",
"1.50172117", "1.508521601", "1.53030303", "1.532658694",
"1.537642783",
"1.54340949", "1.558746736", "1.595342983", "1.596774194",
"1.596969697",
"1.630653266", "1.702558635", "1.70468948", "1.718568102",
"1.740819711",
"1.760157274", "1.775510204", "1.804859813", "1.814081408",
"1.816513761",
"1.849050827", "1.870188679", "1.880195599", "1.887061404",
"1.91858679",
"1.929152149", "1.944140197", "1.946996466", "1.986547085",
"2.007683864",
"2.070983811", "2.099778271", "2.156359393", "2.159613059",
"2.163963964", "2.25951087", "2.261603376", "2.329896907",
"2.402555911", "2.414500684",
"2.444075305", "2.450268817", "2.484520124", "2.51119403",
"2.515064562",
"2.526086957", "2.554", "2.609715243", "2.61965812", "2.643854749",
"2.704166667", "2.883275261", "3.013186813", "3.02739726",
"3.206896552",
"3.320930233", "3.411627907", "3.688931298", "3.709677419",
"3.748267898",
"3.878865979", "3.936440678", "3.994230769", "33.15909091",
"4.095854922",
"4.29330254", "4.390957447", "4.514634146", "4.6367713",
"4.847665848",
"5.284023669", "5.387755102", "6.171339564", "6.183908046",
"6.36121673",
"6.847826087", "7.003496503", "7.193220339", "8.160550459",
"8.751879699"
), class = "factor"), MnFe = c(0.012176723, 0.010329834,
0.009460859,
0.004488071, 0.0033725, 0.003435313), MnIncCoh = c(169.4430276,
331.1977339, 490.5686845, 279.5752228, 272.3091921, 286.0408118
), CuRb = c(0.392971246, 1.484304933, 0.735426009, 0.491651206,
1.142857143, 0.4345898)), row.names = c(NA, 6L), class =
"data.frame")

Using your posted data. This should approximate the desired design.
First step, Transform the data from a wide format to a long format using the pivot_longer function from tidyr.
Then plot the data using "depth" as the independent variable and the parameters' values as the dependent variables.
Then use facet_wrap() to separate the plots. coord_flip() will make the independent variable (Depth) appear on the y-axis.
#fixed 1 column of data.
originaldata$ZrRb <- as.numeric(as.character(originaldata$ZrRb))
library(tidyr)
#Make wide
wapITRAX<-pivot_longer(originaldata, -1, names_to="parameter", values_to = "value")
library(ggplot2)
ggplot(wapITRAX, aes(x = Depth , y = value))+
labs(x = "Depth (cm)")+
geom_line() +
theme_classic() +
coord_flip() +
scale_x_reverse() +
facet_wrap(vars(parameter), nrow=1, scales = "free_x")

Related

How to color scatter plot points based on temporal sequence

I have a dataframe with observations of a temporal event. I can easily plot the observations based on their Xand Y values, either in base R or ggplot2:
plot(df$Y ~ df$X)
ggplot(df, aes(x=X, y=Y)) +
geom_point()
What I'd like to do though is add in the temporal dimension by coloring the observations differently depending on the time they were made. This could be done by defining thresholds for different time steps and assigning discrete colors to each time step. But what I'm interested in is a continuous coloring where the flow of time can be directly read off the flow of colors or color hues or color transparencies. Any help is greatly appreciated.
Reproducible data (slightly shorter than data underlying shown graphs):
structure(list(X = c(171.000358830368, 171.453956550099, 171.075127685269,
171.140924277581, 171.271520544141, 171.582558980529, 171.23762532992,
171.70218914837, 171.318375693213, 170.939546828382, 171.70218914837,
171.779948757467, 171.809856299427, 172.066064242221, 171.603494259901,
171.718139837416, 171.947430992445, 171.930483385334, 172.002261486039,
172.153793031971, 122.654817251517, 171.710164492893, 172.012230666692,
171.395138384244, 171.750041215507, 171.631407965731, 171.927492631138,
172.059085815763, 171.816834725885, 170.787018364384, 170.328436054326,
170.083194210252, 170.405198745358, 170.505887469957, 170.429124778926,
171.187779426653, 171.00634033876, 170.984408141322, 170.731190952725,
170.924593057402, 170.570687144205, 170.751129314032, 170.539782684179,
170.561714881617, 170.461026157017, 170.631499146191, 170.686329639785,
170.863781055416, 170.782033774058, 170.655425179759, 170.645455999106,
170.612557702949, 170.658415933955, 170.514859732545, 170.382269629855,
170.167932245806, 170.187870607113, 169.841940038438, 175.365863038509,
190.973612269532, 206.626222813496, 214.924568789419, 214.509850874236,
211.538038121446, 209.610995501136, 207.007045514458, 204.585531533737,
202.489012842319, 200.693563406635, 199.331773329375, 198.61997383072,
198.494362154486, 202.238786407918, 205.8695620019, 206.616253632843,
207.53541208909, 208.81146721273, 209.850255836818, 210.903998231887,
211.630751501523, 211.825150524265, 211.487195300113, 210.759445112412,
209.407624215806, 207.816542983517, 205.843642132201, 203.585622714198,
201.110275157949, 198.862224920598, 196.914247020916, 195.676074783759,
195.283289066014, 196.015026925976, 197.60710507633, 200.479226022586,
204.110001616568, 207.405812740595, 210.878078362188, 214.015379513825,
216.768867210305, 218.423751198776, 219.404718575074, 219.467524413191,
218.760709504862, 217.317172146244, 215.572565531892, 213.46408382369,
211.338654508377, 209.181323814973, 207.720838849244, 206.537497105681,
205.904454134187, 205.898472625795, 205.953303119389, 206.365030280376,
206.977137972497, 208.319986606516, 209.067675155523, 209.547192744954,
210.106463779612, 210.356690214013, 210.602928976153, 210.692651602034,
210.849167738293, 210.88405987058, 210.998705448095, 211.037585252643,
210.902004395756, 210.895025969299, 210.958828725481, 210.92692734739,
210.975776332592, 211.201079815359, 211.164193846942, 211.304759294155,
210.646793371028, 198.816366689593, 179.579835700717, 164.568243472769,
159.956500502489, 159.636489803513, 159.535801078913, 159.997374143168,
160.238628314981, 160.281495791791, 160.576583539133, 160.637395541118,
156.724492134644, 153.810500629644, 153.846389679996, 154.022844177562,
154.29300897327, 154.442546683072, 154.536256981214, 154.665856329709,
154.665856329709, 154.833338564686, 156.847113056681, 176.676810294436,
177.112463488991, 176.71868085318, 176.042770404877, 175.822451512436,
175.75964567432, 176.817375741649, 176.028813551962, 176.347827332872,
176.622976718907, 182.215687065486, 118.910392998086, 174.380907989949,
171.889609744655, 168.855988071813, 164.924143222097, 160.275514283399,
156.671655477181, 154.165403460906, 107.676123319726, 107.769833617868,
108.581324923058, 109.676937876871, 109.244275436511, 110.393721965853,
161.248506315174, 163.97707106002, 165.507340290323, 166.298893234206,
168.008607716271, 169.06434394747, 170.018394536004, 170.41118025375,
170.202824378093, 170.201827460028, 121.025853132745, 117.483803246579,
120.870333914552, 166.984772863163, 166.489304584687, 168.118268703459,
181.382263562859, 196.653054487796, 135.095357788943, 135.297732156208,
202.44614536551, 203.460011037964, 204.440978414263, 205.227546767819,
205.43490572541, 204.935449774673, 203.891676560258, 202.264706277617,
199.827241607851, 176.081650209426, 194.729002621683, 194.670184455827,
191.186952735516, 190.463190220076, 190.508051533017, 191.482040482858,
186.606114225261, 171.208714706025, 158.889798172571, 149.82880987666,
152.986049389604, 156.597883540345, 159.647455902232, 161.754940692369,
162.893421122992, 114.542894953814, 162.976165322415, 114.268742485845,
160.762010299286, 159.259654774813, 157.995562667957, 156.561994489993,
155.638848361484, 154.469463470836, 154.00390273432, 154.431580584353,
154.255126086787, 155.244068807608, 157.058459686534, 159.101144802424,
161.906472238301, 165.29399982434, 120.406767014167, 172.028181355737,
175.03588315888, 177.740521870158, 179.910812498411, 181.483949205524,
181.988389746588, 181.854802725832, 180.508963337618, 178.901931416283,
176.58609075049, 173.537515306668, 170.679351213327, 167.374567826712,
164.487493109477, 162.203553821774, 160.569605112675, 159.562717866678,
159.828894990125, 159.632502131252, 160.2495944137, 161.450880682439,
162.705003608642, 164.622077048298, 166.212161362521, 167.468278124855,
168.602770883216, 169.155063491416, 169.462114255542, 169.404293007752,
169.003531945484, 168.422328713389, 167.728473739909, 166.825265972708,
165.984864043623, 169.386348482576, 183.504702123976, 200.99862033463,
214.553715269111, 218.552353629205, 217.590327696148, 217.000152201465,
216.115885877505, 215.405083296914, 214.675339273083, 214.063231580962,
213.56477254829, 212.972603217475, 212.488101037718, 212.097309156103,
211.685581995116, 211.786270719716, 211.46426618461, 210.97178866033,
210.657759469747, 210.36167480434, 210.032691842776, 209.635918452769,
209.435537921635, 209.197274504018, 209.046739876151, 208.712772324261,
208.585166811897, 208.3319496233, 203.956476234505, 189.73444311431,
179.21097601654, 176.815381905519, 177.826256823777, 175.90718954799,
175.461567172782, 177.582011897768, 177.488301599626, 177.463378647992,
177.577027307441, 177.676719113976, 177.633851637166, 177.843204430888,
177.995732894886, 177.92196095805, 176.699739409939, 176.824354168107,
176.859246300394, 176.68877331122, 175.325986315895, 176.695751737677,
174.103764767783, 176.520294158177, 178.304777495142, 176.684785638959,
176.697745573808, 177.861148956064, 176.614004456319, 176.121526932039,
176.364774939983, 173.25239673998, 176.064702602315, 174.207444246579,
174.133672309744, 173.831606135945, 174.066878799366, 174.03597433934,
175.830426856959, 174.100774013587, 174.019026732229, 173.965193156701,
173.955223976047, 174.028995912883, 173.886436629538, 174.420784712563,
179.872929611928, 198.741597834692, 208.031877285631, 208.418681494985,
208.232257816765, 247.112062365176, 207.772678588642, 207.722832685375,
207.639091567886, 207.613171698187, 207.569307303312, 207.722832685375,
207.850438197739, 208.002966661736, 208.157488961865, 208.43463218403,
208.722741504914, 209.112536468464, 209.628940026312, 210.13038981318,
211.046557515231, 211.660659043483, 212.448224315105, 213.349438246175,
212.024534137333, 215.36321273817, 216.563502088844, 217.81264042472,
217.271313915238, 218.686937568026, 220.266055783531, 221.81426953901,
223.14814591044, 224.246749618449, 225.106092990776, 225.724182191289,
226.127934007753, 226.088057285139, 225.885682917874, 225.557696874376,
225.048271742986, 257.697338382997, 223.992535511786, 223.464168937154,
223.130201385264, 222.831125965661), Y = c(150.561649721083,
150.067708443465, 150.155166858818, 149.178216605502, 149.407794945803,
148.660423032789, 148.913853668186, 148.276798619991, 148.487493893341,
147.692417390134, 148.3284785927, 147.692417390134, 147.963737246853,
147.216365333839, 147.264069924031, 145.992941364529, 145.626212327424,
144.316323788391, 144.345145311632, 143.45465962804, 118.779460351005,
143.071035215242, 143.299619709914, 142.858352250634, 142.574112400738,
141.615051368744, 141.139993158078, 140.643070343573, 140.190870582374,
140.33597204421, 140.341935117984, 139.946384557638, 140.207765958067,
139.045960417756, 139.269575684283, 138.122677828407, 138.177339338002,
137.268964433088, 137.874216421154, 137.406115129891, 138.076960929472,
137.840425669768, 138.343311558047, 137.691348825417, 138.413874597706,
137.837444132881, 138.70109598449, 138.061059399408, 138.395985376384,
137.616810403241, 138.267779290242, 137.52736429663, 138.054102480005,
137.291822882555, 137.941797923927, 137.242130601105, 137.811604146527,
137.343502855264, 137.326607479571, 135.242513195539, 137.238155218589,
138.312502343547, 139.236778778526, 138.86110513076, 139.273551066799,
138.584816045896, 138.903840492808, 137.509475075308, 137.144733729462,
135.697694493625, 135.567500716225, 134.488184363121, 135.142134787009,
134.959267191271, 135.420411563131, 134.819134957581, 135.649989903432,
135.13120248509, 136.041565081262, 135.646014520916, 136.444072561011,
135.969014350344, 136.521592520073, 135.799066747784, 136.416244883398,
135.748380620704, 136.195611153758, 135.349848523472, 135.534703810467,
134.372898270156, 134.413645940945, 133.470486439016, 133.743793986993,
133.129597388266, 133.61658174648, 133.007354375898, 133.341286507245,
132.799640639435, 133.348243426648, 132.845357538369, 133.241901944344,
132.396139314057, 132.584969983569, 131.617958186543, 131.839585761812,
130.896426259883, 130.981896983977, 129.944322147292, 129.993020583113,
128.968365739605, 128.960414974573, 127.798609434262, 128.082849284158,
127.096954420181, 127.450763464109, 126.738176148109, 127.149628238519,
126.326724057699, 127.023409843635, 126.595062377532, 127.240068190759,
126.893216066235, 127.574000322106, 127.072108279456, 127.73997254215,
127.304668156644, 128.098750814222, 127.663446428716, 128.521135206551,
128.014273935757, 128.852085801011, 128.420756798021, 129.41460242703,
128.987248806556, 129.867796033858, 129.49510392298, 129.345033233,
128.14148617627, 130.371675767766, 130.815924763933, 131.900210345182,
131.529505925561, 132.387194703396, 131.814739621087, 132.715163760969,
132.186437886336, 133.071954341783, 132.563105379731, 133.595710988271,
133.373089567373, 134.173135298725, 133.956476951601, 134.797270353743,
134.562722785297, 135.403516187438, 135.163005545218, 135.992866645441,
131.572241287609, 129.463300862852, 122.968519677278, 123.474387102444,
123.527060920781, 124.246605156184, 123.732786965986, 117.399008772312,
123.862980743386, 124.421521986889, 123.70893467089, 124.808127936574,
126.778923818898, 124.377792779213, 122.935722771521, 124.517925012903,
124.076657553623, 124.838937151073, 124.239648236781, 124.81210331909,
125.153986215469, 125.120195464083, 123.901740722918, 123.046039636341,
120.966914580454, 120.263271875116, 121.53241274336, 121.521480441441,
120.071459668717, 121.39228050967, 120.229481123729, 120.093324272555,
118.693989626911, 118.729768069555, 117.589827133082, 118.195079121148,
108.618382640018, 113.465367772695, 107.992259893742, 117.911833116881,
117.31055651133, 118.451491293432, 122.158535489636, 128.127572337464,
125.310019979223, 125.468041434236, 128.644372064548, 129.146264107198,
128.288575329363, 128.90376577372, 128.18124000143, 128.778541224465,
128.358144523394, 129.135331805279, 128.537036736615, 128.94351959888,
128.079867747271, 127.956630889274, 126.952846803975, 126.741157684996,
125.517733715686, 125.563450614621, 124.14026367388, 123.462460954896,
122.454701487081, 125.26330923466, 123.721854664067, 123.747694650421,
122.82639975233, 123.206048782611, 122.267858508827, 115.131053046914,
122.130707812024, 114.510893374412, 122.343390776632, 123.249777990288,
122.697199820559, 123.432645586025, 123.527060920781, 123.925593018014,
123.003304274293, 124.011063742109, 123.917642252982, 125.041681659391,
124.907512499475, 125.786072035519, 125.602210594152, 126.27603793062,
114.507911837525, 126.00571191953, 125.382570710141, 125.88446275279,
125.144047759179, 125.545561393298, 124.766386420155, 124.993977069198,
124.193931337846, 124.197906720362, 123.290525661077, 123.403824062784,
122.544147593691, 122.783664390282, 121.98361865893, 122.607753713948,
122.271833891343, 122.822424369814, 122.699187511817, 122.789627464057,
122.228104683666, 122.501412231644, 121.437997408604, 121.568191186005,
120.996729949324, 121.368428214574, 120.744293159556, 121.303828248688,
120.7800716022, 121.339606691332, 120.856597715634, 121.619871158713,
121.218357524593, 121.974674048269, 121.564215803488, 122.684279827382,
121.975667893898, 124.308223585182, 126.514560881582, 128.363113751539,
128.091793894819, 128.702015111031, 128.509209059003, 129.155208717859,
128.840159653463, 129.56566696264, 129.235710213809, 130.013891341323,
129.748534558377, 130.711570972887, 130.380620378427, 129.980100589936,
129.586537720849, 130.563487974165, 130.419380357958, 131.614976649656,
131.552364375028, 132.790696028774, 132.718145297856, 133.984304629213,
134.010144615568, 135.165987082105, 135.426374636905, 136.790924685535,
135.130208639461, 129.957242140469, 126.592080840645, 127.358335820611,
127.887061695243, 129.049861081184, 128.986254960927, 130.73840480487,
130.834807830884, 132.108917927273, 132.045311807017, 133.056052811719,
132.901012893594, 133.848147778039, 133.514215646692, 134.505079738814,
134.604464301715, 135.360780825391, 135.037780995963, 135.768257533284,
134.735651924744, 135.809999049703, 134.344076746915, 135.788134445865,
127.311625076047, 135.801054439042, 135.322020845859, 127.889049386501,
135.320033154601, 135.615205306417, 126.665625417191, 134.175122989983,
126.25616101804, 134.430541316638, 133.848147778039, 134.240716801498,
133.809387798508, 134.271526015997, 126.20547489096, 134.244692184014,
133.780566275267, 134.294384465464, 133.818332409169, 134.256618331562,
133.891876985716, 134.534895107684, 127.426911169012, 142.477709374724,
146.033689035318, 147.092134630213, 146.619064110804, 170.36998695286,
146.552476453661, 147.216365333839, 146.709504063044, 147.474765197381,
147.046417731278, 147.842488080114, 147.290903756014, 148.023367984594,
147.353516030642, 147.901124972226, 147.171642280533, 147.729189678407,
147.072257717632, 147.535389780751, 147.15474690484, 146.832740921041,
146.568377983725, 146.13207975259, 144.739702026348, 145.216747928273,
144.640317463447, 144.137431575169, 143.147561328676, 141.941032735059,
141.073405500934, 140.496975036109, 140.057695268087, 139.778424646336,
139.654193942709, 139.203981872768, 138.923717405388, 138.393997685126,
137.79868415335, 137.209333695347, 136.706447807069, 165.401752653445,
135.932242062071, 135.629119145223, 135.168968618992, 134.679002723891
), starttime_ms = c(310849, 310865, 310882, 310899, 310915, 310932,
310949, 310965, 310982, 310999, 311015, 311032, 311049, 311065,
311082, 311099, 311115, 311132, 311149, 311165, 311182, 311199,
311215, 311232, 311249, 311265, 311282, 311299, 311315, 311332,
311349, 311365, 311382, 311399, 311415, 311432, 311449, 311465,
311482, 311499, 311515, 311532, 311549, 311565, 311582, 311599,
311615, 311632, 311649, 311665, 311682, 311699, 311715, 311732,
311749, 311765, 311782, 311799, 311815, 311832, 311849, 311865,
311882, 311899, 311915, 311932, 311949, 311965, 311982, 311999,
312015, 312032, 312049, 312065, 312082, 312099, 312115, 312132,
312149, 312165, 312182, 312199, 312215, 312232, 312249, 312265,
312282, 312299, 312315, 312332, 312349, 312365, 312382, 312399,
312415, 312432, 312449, 312465, 312482, 312499, 312515, 312532,
312549, 312565, 312582, 312599, 312615, 312632, 312649, 312665,
312682, 312699, 312715, 312732, 312749, 312765, 312782, 312799,
312815, 312832, 312849, 312865, 312882, 312899, 312915, 312932,
312949, 312965, 312982, 312999, 313015, 313032, 313049, 313065,
313082, 313099, 313115, 313132, 313149, 313165, 313182, 313199,
313215, 313232, 313249, 313265, 313282, 313299, 313315, 313332,
313349, 313365, 313382, 313399, 313415, 313432, 313449, 313465,
313603, 313619, 313636, 313665, 313682, 313699, 313715, 313732,
313749, 313765, 313782, 313799, 313815, 313832, 313849, 313865,
313882, 313899, 313915, 313932, 313949, 313965, 313982, 313999,
314015, 314032, 314049, 314065, 314082, 314099, 314115, 314132,
314149, 314165, 314182, 314199, 314215, 314232, 314249, 314265,
314282, 314299, 314315, 314332, 314349, 314365, 314382, 314399,
314415, 314432, 314449, 314465, 314482, 314499, 314515, 314532,
314549, 314565, 314582, 314599, 314615, 314632, 314649, 314665,
314682, 314699, 314715, 314732, 314749, 314765, 314782, 314799,
314815, 314832, 314849, 314865, 314882, 314899, 314915, 314932,
314949, 314965, 314982, 314999, 315015, 315032, 315049, 315065,
315082, 315099, 315115, 315132, 315149, 315165, 315182, 315199,
315215, 315232, 315249, 315265, 315282, 315299, 315315, 315332,
315349, 315365, 315382, 315399, 315415, 315432, 315449, 315465,
315482, 315499, 315515, 315532, 315549, 315565, 315582, 315599,
315615, 315632, 315649, 315665, 315682, 315699, 315715, 315732,
315749, 315765, 315782, 315799, 315815, 315832, 315849, 315865,
315882, 315899, 315915, 315932, 315949, 315965, 315982, 315999,
316015, 316032, 316049, 316065, 316082, 316099, 316115, 316132,
316149, 316165, 316182, 316199, 316215, 316232, 316249, 316265,
316282, 316299, 316315, 316332, 316349, 316365, 316382, 316399,
316415, 316432, 316449, 316465, 316482, 316499, 316515, 316532,
316549, 316565, 316582, 316599, 316615, 316632, 316649, 316665,
316682, 316699, 316715, 316732, 316749, 316765, 316782, 316799,
316815, 316832, 316849, 316865, 316882, 316899, 316915, 316932,
316949, 316965, 316982, 316999, 317015, 317032, 317049, 317065,
317082, 317099, 317115, 317132, 317149, 317165, 317182, 317199,
317215, 317236, 317253, 317269, 317286, 317303, 317319, 317336,
317353, 317369, 317386, 317403, 317419, 317436, 317453, 317469,
317486, 317503, 317519, 317536, 317553, 317569, 317586, 317603,
317619, 317636, 317653)), row.names = c(123318L, 123324L, 123333L,
123343L, 123354L, 123363L, 123370L, 123373L, 123376L, 123384L,
123391L, 123399L, 123406L, 123414L, 123424L, 123434L, 123438L,
123440L, 123444L, 123446L, 123449L, 123459L, 123468L, 123477L,
123483L, 123491L, 123502L, 123505L, 123509L, 123516L, 123523L,
123526L, 123532L, 123538L, 123548L, 123556L, 123565L, 123570L,
123574L, 123576L, 123580L, 123586L, 123593L, 123602L, 123611L,
123617L, 123623L, 123627L, 123631L, 123640L, 123648L, 123652L,
123663L, 123671L, 123674L, 123677L, 123684L, 123691L, 123696L,
123706L, 123714L, 123725L, 123733L, 123735L, 123739L, 123741L,
123745L, 123751L, 123756L, 123766L, 123775L, 123777L, 123786L,
123794L, 123800L, 123807L, 123813L, 123816L, 123819L, 123823L,
123833L, 123842L, 123850L, 123861L, 123869L, 123876L, 123884L,
123892L, 123897L, 123904L, 123910L, 123912L, 123917L, 123926L,
123933L, 123939L, 123945L, 123949L, 123953L, 123956L, 123962L,
123968L, 123975L, 123981L, 123988L, 123996L, 124005L, 124015L,
124020L, 124023L, 124029L, 124036L, 124045L, 124054L, 124063L,
124069L, 124079L, 124085L, 124094L, 124103L, 124112L, 124117L,
124124L, 124127L, 124130L, 124137L, 124146L, 124158L, 124169L,
124177L, 124184L, 124189L, 124195L, 124203L, 124213L, 124220L,
124227L, 124234L, 124244L, 124252L, 124257L, 124259L, 124262L,
124265L, 124271L, 124279L, 124291L, 124299L, 124304L, 124312L,
124321L, 124324L, 124328L, 124337L, 124343L, 124347L, 124354L,
124363L, 124415L, 124424L, 124426L, 124435L, 124440L, 124446L,
124454L, 124461L, 124467L, 124469L, 124476L, 124486L, 124493L,
124496L, 124504L, 124510L, 124519L, 124524L, 124531L, 124539L,
124550L, 124555L, 124558L, 124560L, 124564L, 124569L, 124579L,
124586L, 124595L, 124599L, 124608L, 124617L, 124622L, 124629L,
124634L, 124636L, 124640L, 124645L, 124653L, 124660L, 124669L,
124681L, 124694L, 124700L, 124709L, 124716L, 124722L, 124727L,
124730L, 124733L, 124738L, 124743L, 124748L, 124755L, 124766L,
124774L, 124782L, 124786L, 124793L, 124801L, 124808L, 124812L,
124821L, 124831L, 124844L, 124852L, 124861L, 124867L, 124873L,
124877L, 124883L, 124890L, 124901L, 124912L, 124917L, 124921L,
124926L, 124934L, 124943L, 124948L, 124956L, 124958L, 124962L,
124968L, 124977L, 124986L, 124995L, 125005L, 125013L, 125015L,
125018L, 125025L, 125036L, 125046L, 125051L, 125056L, 125063L,
125072L, 125076L, 125078L, 125082L, 125084L, 125091L, 125100L,
125111L, 125118L, 125128L, 125135L, 125143L, 125147L, 125155L,
125165L, 125168L, 125170L, 125178L, 125188L, 125195L, 125203L,
125212L, 125217L, 125220L, 125222L, 125226L, 125238L, 125245L,
125252L, 125256L, 125262L, 125269L, 125278L, 125285L, 125288L,
125292L, 125296L, 125307L, 125319L, 125322L, 125325L, 125329L,
125334L, 125342L, 125351L, 125360L, 125372L, 125379L, 125386L,
125389L, 125392L, 125397L, 125402L, 125411L, 125421L, 125428L,
125436L, 125446L, 125451L, 125457L, 125459L, 125465L, 125470L,
125477L, 125483L, 125490L, 125499L, 125508L, 125515L, 125523L,
125526L, 125532L, 125540L, 125548L, 125550L, 125553L, 125558L,
125564L, 125570L, 125580L, 125588L, 125594L, 125600L, 125604L,
125610L, 125617L, 125624L, 125633L, 125640L, 125647L, 125655L,
125661L, 125669L, 125676L, 125679L, 125686L, 125695L, 125706L,
125716L, 125725L, 125733L, 125737L, 125743L, 125755L, 125758L,
125762L, 125764L, 125769L, 125775L, 125783L, 125790L, 125800L,
125808L, 125815L, 125823L, 125828L, 125834L, 125838L, 125845L,
125852L, 125864L, 125871L, 125880L, 125889L, 125893L, 125896L,
125899L, 125902L, 125904L, 125912L, 125920L, 125931L, 125936L,
125944L, 125952L, 125961L, 125963L, 125969L, 125978L, 125984L,
125991L, 126002L, 126009L, 126018L, 126025L, 126028L), class = "data.frame")
You could do:
library(ggplot2)
ggplot(df, aes(x = X, y = Y, color = starttime_ms)) +
geom_point() +
scale_color_gradientn(colors = c("red", "gold", "forestgreen"), name = "time")
An alternative that might help keep track of the motion better would be to use geom_segment:
df$X2 <- dplyr::lag(df$X)
df$Y2 <- dplyr::lag(df$Y)
ggplot(df, aes(x = X, y = Y, color = starttime_ms)) +
geom_segment(aes(xend = X2, yend = Y2), size = 1) +
scale_color_gradientn(colors = c("red", "gold", "forestgreen"), name = "time")

gganimate zoom in on data while keeping map as background doesnt work

I am trying to plot a path of gps points I have (the included example is a of a train ride in the Netherlands). I would like to make use of the
shadow_mark() and view_follow() functions of the gganimate() package, such that the plot starts fully zoomed in and then progressingly zooms out. This works fine if I do not use either google or OSM map as a background, but I would like to use one of these (not picky). I have tried to play around with
the exclude_layer = command, but cannot seem to get it to work. If I use a map as background the animation is zoomed out from the 1st frame.
I looked around the vignettes, but could not find an example of view_follow() being used together with a map as background.
Set up packages and data (200 gps points)
require(gganimate)
require(tidyverse)
require(lubridate)
require(ggmap)
library(OpenStreetMap)
df3 <- structure(list(lat = c(52.0473442, 52.0173027, 52.0898208, 52.0309643,
52.0497488, 52.0897325, 52.0892640857143, 52.0179681, 52.0383389,
52.1048323, 52.0181769, 52.0289188, 52.0941033, 52.0182591, 52.0882347,
52.090628, 52.1060504, 52.0893178, 52.1062902, 52.015563475,
52.1041445, 52.09096297, 52.0095689, 52.0460849, 52.0949215,
52.0243182, 52.066435, 52.0273662, 52.1055631, 52.0893175, 52.0487954,
52.0980435, 52.09089341, 52.0145649, 52.0089167, 52.0605713,
52.009809, 52.0895006516129, 52.0893323, 52.0959561, 52.0659477,
52.0514133, 52.08956736, 52.0898078, 52.0971748, 52.0131978,
52.049002, 52.0182712, 52.1045885, 52.0895501, 52.062702, 52.0919686,
52.0163620216216, 52.09101514, 52.0895122571429, 52.0906238,
52.1049253, 52.0085885, 52.0948177, 52.0906366, 52.0894994903226,
52.103213, 52.0372776, 52.0468101, 52.0485351, 52.0874545, 52.0392919,
52.0892646285714, 52.08922625, 52.0143929, 52.0503487, 52.0598063,
52.0894236363636, 52.0895004193548, 52.0895104285714, 52.08926629,
52.0204065, 52.0494409, 52.0894992580645, 52.0149126096774, 52.0910172,
52.0163522, 52.1038697666667, 52.0175865, 52.1011104, 52.1022396,
52.0508854, 52.0326581, 52.0893379636364, 52.0936814, 52.0608923,
52.0171837, 52.0207873, 52.0892670714286, 52.089319, 52.1019613,
52.1005872, 52.0430951, 52.0898355, 52.0893309181818, 52.0180603,
52.0390661, 52.0348046, 52.0481463, 52.0420622, 52.0167229, 52.0523997,
52.0172069, 52.0412617, 52.0212251, 52.0894450545455, 52.0381603,
52.0988658, 52.0892341636364, 52.0167707108108, 52.0856953, 52.0455796,
52.0893241, 52.0974118, 52.10305028, 52.0975816, 52.0906235,
52.100775, 52.0748232, 52.0102848, 52.089504, 52.0164101027027,
52.0083622, 52.0895125619048, 52.038528, 52.1041174, 52.0963176,
52.0153379, 52.1024123, 52.0895413, 52.0931169, 52.015444875,
52.0386511, 52.0516474, 52.0895002451613, 52.0215369, 52.0991255,
52.0969218, 52.0893316, 52.066435, 52.0139796, 52.0981765, 52.0897099,
52.0352992, 52.051733, 52.0530949, 52.08922647, 52.0107568, 52.0677648,
52.0895214666667, 52.089504648, 52.100359, 52.09324255, 52.0620195,
52.0466879, 52.017858, 52.0135695, 52.0254736, 52.0171776, 52.028283,
52.0171794, 52.1010769, 52.0178973, 52.0924092, 52.0897434, 52.0505729,
52.0291358, 52.0893442, 52.0086011, 52.0992469, 52.059978, 52.0897928,
52.0892269041667, 52.1054074, 52.089251, 52.0526539, 52.0266356,
52.0449901, 52.1051109, 52.0612085, 52.0897635, 52.0618627, 52.0894992,
52.1059497, 52.015919275, 52.0114324, 52.0511659, 52.0892549333333,
52.0235488, 52.0272761, 52.09694, 52.0521608, 52.0153993, 52.1060753,
52.0175162), lon = c(4.8527414, 4.7043579, 5.1092251, 4.558967,
4.4474887, 5.1093993, 5.10904667619048, 4.7878027, 4.8367076,
4.95351535, 4.6931897, 4.567024, 5.105847, 4.6899796, 4.9029363,
5.1110543, 4.96241255, 5.108432375, 4.9690878, 4.73307101555556,
4.9939, 5.110891905, 4.6441234, 4.496551, 5.1049426, 4.5854403,
4.3598875, 4.8104103, 4.9753691, 5.10843242142857, 4.4603587,
4.9321842, 5.110488365, 4.624286, 4.6469115, 4.865213, 4.6431315,
5.1097292516129, 5.10848633, 4.9263356, 4.3614653, 4.4245138,
5.10908557, 5.1092372, 4.929797, 4.6298071, 4.8542748, 4.691945,
4.9882762, 4.9068603, 4.3707472, 5.1076963, 4.71963735765766,
5.11119456, 5.10973931428571, 5.1110549, 4.9540848, 4.6488539,
5.1050478, 5.1110486, 5.10973009032258, 5.0053341, 4.8341014,
4.4882284, 4.4640663, 4.9004724, 4.8388151, 5.10903851428571,
5.10884365, 4.7520508, 4.4393094, 4.8644185, 5.10953031818182,
5.10972941935484, 5.10973205714286, 5.10849255, 4.601082, 4.4515908,
5.10973025806452, 4.74402028494624, 5.1111849, 4.676354, 4.99798836666667,
4.7009575, 5.031704, 5.0167332, 4.4321563, 4.8230864, 5.10928108181818,
5.1062712, 4.3758328, 4.7058636, 4.5995564, 5.10900178571429,
5.10843218928571, 5.0200993, 5.0389258, 4.8472408, 5.1091899,
5.10847912727273, 4.6946867, 4.5265032, 4.8282194, 4.4697327,
4.5144658, 4.6157094, 4.4114789, 4.6803854, 4.8436428, 4.5977714,
5.10959262727273, 4.8362508, 5.0669724, 5.10884347272727, 4.71276212882883,
4.8951137, 4.5001568, 5.1084314, 5.0888354, 5.0070498, 5.0845948,
5.1110552, 5.0356131, 4.878915, 4.6636436, 5.10892755, 4.71882850720721,
4.65157, 5.10974052380952, 4.8371255, 4.9957208, 5.1016242, 4.673318,
5.0145183, 5.1100309, 5.1067818, 4.73506618, 4.5281429, 4.4214528,
5.10972954516129, 4.7963679, 5.0638705, 5.0952241, 5.1084839,
4.3598875, 4.7581467, 5.0759648, 5.1094376, 4.829447, 4.4204181,
4.4020959, 5.10884371, 4.6393904, 4.3563094, 5.109842, 5.109726984,
5.0417278, 4.91819815, 4.3726141, 4.4892613, 4.6975655, 4.6697432,
4.580841, 4.7058672, 4.8126885, 4.7058869, 4.9413298, 4.6971556,
4.9156515, 5.109391, 4.4370594, 4.5661368, 5.10852764, 4.6569508,
5.0618936, 4.3785312, 5.1092584, 5.108826925, 4.9785586, 5.10890992857143,
4.8577536, 4.5762531, 4.5027296, 4.9817912, 4.3749189, 5.1093724,
4.373075, 5.1097303, 4.9606803, 4.72708552222222, 4.6660585,
4.4280254, 5.1089249, 4.5886027, 4.5736119, 5.0948948, 4.4141114,
4.7804527, 4.97133625, 4.6823925), time = structure(c(1549542028,
1549541565, 1549542658, 1549541192, 1549540912, 1549542689, 1549542880,
1549541872, 1549541986, 1549542287, 1549541524, 1549541210, 1549542600,
1549541514, 1549542184, 1549543182, 1549542303, 1549543013, 1549542315,
1549541756, 1549542360, 1549543125, 1549541393, 1549541039, 1549542592,
1549541253, 1549540695, 1549541925, 1549542326, 1549543012, 1549540937,
1549542243, 1549543129, 1549541352, 1549541399, 1549542075, 1549541391,
1549542809, 1549543046, 1549542231, 1549540734, 1549540867, 1549543079,
1549542660, 1549542238, 1549541363, 1549542034, 1549541520, 1549542350,
1549542192, 1549540756, 1549542623, 1549541704, 1549543122, 1549542766,
1549543211, 1549542288, 1549541403, 1549542593, 1549543174, 1549542829,
1549542381, 1549541980, 1549541009, 1549540944, 1549542179, 1549541991,
1549542882, 1549542947, 1549541800, 1549540896, 1549542072, 1549542861,
1549542813, 1549542772, 1549543000, 1549541296, 1549540920, 1549542833,
1549541784, 1549543143, 1549541474, 1549542368, 1549541550, 1549542428,
1549542401, 1549540882, 1549541954, 1549542869, 1549542604, 1549540767,
1549541600, 1549541292, 1549542891, 1549543017, 1549542407, 1549542441,
1549542011, 1549542653, 1549543044, 1549541529, 1549541119, 1549541966,
1549540955, 1549541091, 1549541333, 1549540842, 1549541485, 1549542002,
1549541287, 1549542859, 1549541985, 1549542493, 1549542970, 1549541687,
1549542168, 1549541052, 1549543034, 1549542539, 1549542384, 1549542529,
1549543225, 1549542435, 1549542125, 1549541436, 1549543075, 1549541702,
1549541409, 1549542765, 1549541987, 1549542364, 1549542577, 1549541466,
1549542397, 1549542736, 1549542610, 1549541764, 1549541123, 1549540861,
1549542816, 1549541892, 1549542487, 1549542555, 1549543045, 1549540730,
1549541812, 1549542511, 1549542701, 1549541969, 1549540859, 1549540824,
1549542949, 1549541383, 1549540720, 1549542756, 1549542791, 1549542446,
1549542215, 1549540760, 1549541013, 1549541538, 1549541455, 1549541242,
1549541668, 1549541930, 1549541670, 1549542262, 1549541537, 1549542210,
1549542688, 1549540892, 1549541208, 1549543063, 1549541420, 1549542483,
1549540773, 1549542679, 1549542925, 1549542332, 1549542906, 1549542047,
1549541231, 1549541060, 1549542338, 1549540765, 1549542686, 1549540761,
1549542834, 1549542300, 1549541732, 1549541443, 1549540874, 1549542904,
1549541261, 1549541225, 1549542554, 1549540847, 1549541856, 1549542319,
1549541491), class = c("POSIXct", "POSIXt"), tzone = "Europe/Paris")), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -200L), .Names = c("lat",
"lon", "time"))
load maps as background
LAT1 = in(df3$lat) -.07
LAT2 = max(df3$lat) +.07
LON1 = min(df3$lon) -.07
LON2 = max(df3$lon) +.07
map_osm <- openmap(c(LAT2,LON1), c(LAT1,LON2), zoom = NULL,
type = "stamen-toner",
mergeTiles = TRUE,
minNumTiles=10)
map_osm <- openproj(map_osm, projection = "+proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs")
map_google_box <- make_bbox(lat = df3$lat, lon = df3$lon, f = 0.5)
map_google <- get_map(location = map_google_box)
animations
# this works
ani1 <- ggplot()+
geom_point(data = df3,
aes(y =lat, x= lon),
size = 2,
col = 'red')+
transition_time(time) +
ease_aes('linear')+
shadow_mark()+
view_follow()
animate(ani1)
# this doesnt
ani2 <- ggmap(map_google) +
geom_point(data = df3,
aes(y =lat, x= lon),
size = 2,
col = 'red')+
transition_time(time) +
ease_aes('linear')+
shadow_mark()+
view_follow()
animate(ani2)
# this doesnt either
ani3 <- autoplot(map_osm) +
geom_point(data = df3,
aes(y =lat, x= lon),
size = 2,
col = 'red')+
transition_time(time) +
ease_aes('linear')+
shadow_mark()+
view_follow()
animate(ani3)

Scatterplot/volcano plot as an output from t.test

It is my data:
> dput(data)
structure(list(foldchange = c(-0.17853057272962, 3.60013440830337,
0.648944710423407, 1.38528656859267, 2.38882890772698, 1.91371568283765,
1.77591931363495, -1.51447851175922, 3.1416903855924, 1.51711016957237,
3.14707703341916, -1.44751697381751, 1.23658565660726, -0.512829478520189,
1.68928069854351, 2.07214007434345, 1.24799276690488, 6.25149659558487,
6.35918877435554, 5.86088034655694, 6.38890659730165, 5.05510489389194,
4.62060389613534, 3.75508710774868, 4.18575763169519, 5.31627264153051,
5.87091236649665, 6.71464565321037, 5.24000610137973, 4.25821377851955,
7.32277714374523, 3.1963295806222, 7.26249808789293, 4.44427454088613,
6.21495395454133, 8.74469985969472, 7.49982946564144, 4.45020943795387,
5.66199031471621, 5.29959827685333, 8.65819317196484, 5.86664903755707,
4.5740575604176, 8.24504501687473, 5.7916074097308, 4.18199181353134,
6.73956641707995, 4.60357435173805, 5.9205153184753, 3.65014593638562,
3.25607795403669, 5.56919529940933, 5.76811109641351, 6.10600807588152,
5.69234974521511, 5.5102283323841, 4.71232921328194, 6.55727667796477,
6.19995053763513, 4.64209842048131, 2.29238227264409, 6.79465189260383,
7.51968952300944, 7.81695579226993, 6.29926703626301, 4.64687557749141,
-2.44220257171186, 5.33199370895397, 5.18820654974805, 5.03498241997507,
6.29395095024283, 6.27602377186869, 6.78363927671209, 2.93759015053983,
6.65061604346668, 5.671080311536, 8.45199131823131, 5.79230415012306,
6.3270025568739, 7.0934690916107, 3.53800869528685, 3.08683779646569,
6.82111375813946, 3.02729078403818, 5.36024214796805, 4.04778690916444,
5.74765756930797, 4.10788604670319, 6.39978058654016, 5.7746717387066,
2.9247167920294, 7.54315906042106, 4.2742172444481, 6.61121261965006,
3.77012175922873, 4.94407566887151, 7.93185716981795, 7.05304621480995,
5.59261760605766, 5.42381827536197, 4.22645498896606, 5.15806113482742,
4.15403623593809, 6.40153592433128, 7.38902001442131, 2.72654942454391,
3.28741231093207, 3.79334363176751, 5.86527050546341, 5.10320299162235,
3.99883612485974, 6.45475273104195, 4.85567883821983, 6.55055641729645,
5.03746875764267, 7.27660375171087, 3.30817125205364, 5.23766518187252,
7.6588755830143, 3.53552741086444, 5.66455197986778, 8.40623211540503,
3.93151438658523, 4.26875667827774, 4.38704995079332, 6.75232207417316,
3.76563594385214, 6.08008097541859, 2.40905905886796, 5.50981339395085,
5.78780269825563, 0.2322416329745, 5.69410860233132, 4.94656296117567,
4.20594226169741, 4.50293112094816, 6.07430576125864, 3.67684848946483,
5.825851099141, 5.22439201628482, 7.72829018644622, 5.24910611944979,
4.01783420322782, 6.3888069709767, 5.26066649741256, 4.81678726754752,
6.5683773907454, 4.86957242886115, 6.76705114368644, 4.45769029291236,
7.77607596853254, 6.85213457577069, 1.40150885676552, 5.43409652313493,
3.21738153172066, 6.23015085020594, 5.50091556711613, 3.99948543388746,
5.85816098688073, 4.33775608630599, 5.91715214825299, 5.45674826103132,
7.66790792082782, 6.63325838131012, 3.89631178894691, 2.38526575667126,
1.58661549426288, 4.76626341270591, 6.73426272316295, 5.54006035262931,
4.07996836453406, 7.12087390022358, 6.96007461543701, 5.68202490906633,
6.58504044389069, 5.41036820315057, 6.61076809589319, 1.23772469006557,
4.1661166499875, 2.94059625298825, 8.38336956160413, 4.84906289871508,
4.93787691221829, 6.82379835301371, 5.82520798412864, 4.87582657907206,
5.36621724700676, 8.91922991774938, 3.49025109999629, 5.1232073414505,
4.27193651596412, 5.07417945071012, 3.61930149745523, 2.7469092502892,
6.67162003616042, 4.86698118654996, 7.53876919017093, 4.58878989189686,
5.78956520376246, 3.98567045767003, 8.14934433289609, 6.88879716040936,
7.00251456012974, 5.05095662412332, 6.39777439550296, 7.96268799093557,
4.82826575143863, 8.31032763539508, 4.74493707321909, 6.8929416113222,
6.84202549278968, 8.20121430968127, 2.91031632522241, 4.86190488550545,
5.5516465446887, 7.74996457744065, 2.25505738807845, 5.71069872298306,
1.97493599527532, 5.60445326341706, 6.39297603198736, 7.16298115056911,
4.52688105225386, 6.46061751569601, 4.78104064111529, 2.84526825975018,
6.5537923066898, 6.98258253798747, 5.0967396817644, 6.64593966293456,
4.8990397150507, 4.59878411928317, 5.55158425631398, 2.1065660739172,
2.40396884881286, 6.45421536580342, 5.98567305090568, 6.48593538806214,
7.41313242816247, 5.99024340460149, 5.63812101302136, -1.43793573368627
), all_pvalue = c(0.818887590433193, 0.00892139546812015, 0.434133425685163,
0.0536266013313456, 0.0450933986128537, 0.0367856407800243, 0.0941222253709068,
0.213526299326008, 0.00855327289085924, 0.0449444491492238, 0.00465098209958804,
0.0369667514121697, 0.0910501610463896, 0.378892060498093, 0.0595757077704777,
0.031626850730261, 0.0878934608628569, 0.0124722939899662, 0.0249040599008334,
0.0150448394759397, 0.0104024068916351, 0.0340577599419123, 0.0244947271472485,
0.122485247246688, 0.0211309039009709, 0.0201043058824927, 0.0152779076456381,
0.00938733157248341, 0.013807428170544, 0.01948348499862, 0.0119978631408916,
0.0997968486684091, 0.00504808432168479, 0.041226720485986, 0.0127407583225205,
0.00709338243276709, 0.00383605674079435, 0.0399854589187244,
0.0163222001450531, 0.00909800553027099, 4.81144191594885e-06,
0.0105231068132293, 0.0377428014886314, 0.00709059633291303,
0.00743882656849872, 0.0696633906261403, 0.00568508439144595,
0.0142206230933159, 0.0183625193075117, 0.0818974933908099, 0.0609423408539195,
0.00581572852382799, 0.00603085345605447, 0.00684099077236254,
0.0194814381299995, 0.0325641567545152, 0.0404062983698557, 0.00626431765905907,
0.00287654691487974, 0.0183318967557602, 0.202860908663261, 0.0033395497287839,
0.00804091896430431, 0.00524635934550195, 0.0100089274728679,
0.00470611875383887, 0.361169323059008, 3.90129727113067e-06,
0.0205225005371219, 0.0120500045076898, 0.00732055098038156,
0.0229916087025324, 0.00544774481324614, 0.108252753362848, 0.00911923198666818,
0.0122812312739145, 0.00343585528287351, 2.06257208918569e-05,
0.000904993210532763, 0.0015065294739414, 0.102118204143709,
0.118350948568527, 0.0136202759386966, 0.15251012082679, 0.0428316882385798,
0.0752744217284719, 0.00632986043900174, 0.0269567937932686,
0.00707537967267082, 0.0149356605279715, 0.163005190656644, 0.00929612911973378,
0.0196453775259569, 0.0133262667903121, 0.114115405959882, 0.0189109801950218,
0.00590387539250432, 0.00802692325541374, 0.0184346327727756,
0.00104714399950925, 0.0554774130259537, 0.0084910975380844,
0.0349856904843115, 0.0124547169142572, 8.60050865459788e-07,
0.1188515828269, 0.133720711339729, 0.0641704698591151, 0.0075124796175742,
3.94432669779951e-07, 0.0740343932996142, 0.00160775849728933,
6.61326355967731e-06, 0.0106610228625055, 0.00539717052083514,
0.00492255859958016, 0.122531121480312, 0.0159768620962635, 0.00365780586610517,
0.0135086464724098, 0.0256265865459836, 0.00391215568816396,
0.0271580638871089, 0.0512876942387616, 0.0135566028247977, 0.0169110062500104,
0.0848247460082605, 0.0158705161056627, 0.176345767878009, 0.0124719098589431,
0.0152388258990332, 0.866066700538701, 0.042979313425954, 0.0160125031962862,
0.0441592105265668, 0.0124108545467876, 1.80875437447348e-06,
0.0704671677844812, 0.0111351361909711, 1.62883074487165e-07,
0.000694779973318456, 0.0120079549431507, 0.0196183531679123,
0.0100186493225724, 0.0173294242221405, 0.0573614373022037, 1.30612522568528e-07,
0.023898721968545, 0.00665918028588502, 0.06907634259105, 0.00518730999717143,
0.0109717740506543, 0.394662670743417, 0.0165847750353483, 0.0593829446004973,
0.000113216713641592, 0.0222583368635018, 0.0694462386106761,
0.00437955933335859, 0.0631677226779205, 0.00649674049335009,
1.10699021652115e-07, 0.00543997929535101, 0.00292890932795308,
0.021574456097881, 0.17997075681454, 0.279770535484078, 0.050945514039484,
0.0102923410906512, 0.0103389721465925, 0.112227938286441, 0.00398090342551613,
0.0428676019413789, 0.00337313863923396, 0.0092822848687081,
0.00778850900332348, 0.00146877357609246, 0.448950342618974,
0.0801294647165026, 0.0797698230881222, 3.72112644308374e-05,
0.00728653989704988, 0.0320006421510141, 0.000420503611946363,
0.0207086037412542, 0.0448889114898146, 6.94555482668648e-07,
0.000135994029220134, 0.0982385638169219, 0.0130399195487442,
0.0297056523919866, 0.0208455457844783, 0.104595177359326, 0.100684824982166,
0.00110472016462074, 0.0664329210478157, 0.0140428240948167,
0.0468861767036331, 0.0102813794498838, 0.0693803856754811, 0.00566014993761021,
0.00275831473628789, 0.00234550137829788, 0.0116252548991317,
0.0143153463606759, 0.00995352784254985, 0.00238257560505637,
0.00182950280683248, 0.013195116994233, 0.000640921917352429,
0.000171523469251389, 0.0087256530793244, 0.0989386901919075,
0.0321103798387662, 0.0222773975090858, 0.007943310795799, 0.171053950985746,
0.012874269835152, 0.38817395138115, 0.00787508757030877, 0.0114487159712535,
0.0187831808209386, 0.0452479566115196, 0.00640720682677851,
0.0315482155790946, 0.125132833439637, 0.0115284490664364, 0.00538397509568388,
0.00517772137814985, 0.00176762574966497, 0.0273122011845722,
0.0191341545126795, 0.0235413416908084, 0.270326642321866, 0.179926862630332,
0.008734949388329, 0.0138918131322944, 0.00507817315892406, 0.000173786133243839,
0.00225184544628237, 0.0181059516295825, 0.541544494598043),
probename = c("Mark_1", "Mark_2", "Mark_3", "Mark_4", "Mark_5",
"Mark_6", "Mark_7", "Mark_8", "Mark_9", "Mark_10", "Mark_11",
"Mark_12", "Mark_13", "Mark_14", "Mark_15", "Mark_16", "Mark_17",
"Mark_18", "Mark_19", "Mark_20", "Mark_21", "Mark_22", "Mark_23",
"Mark_24", "Mark_25", "Mark_26", "Mark_27", "Mark_28", "Mark_29",
"Mark_30", "Mark_31", "Mark_32", "Mark_33", "Mark_34", "Mark_35",
"Mark_36", "Mark_37", "Mark_38", "Mark_39", "Mark_40", "Mark_41",
"Mark_42", "Mark_43", "Mark_44", "Mark_45", "Mark_46", "Mark_47",
"Mark_48", "Mark_49", "Mark_50", "Mark_51", "Mark_52", "Mark_53",
"Mark_54", "Mark_55", "Mark_56", "Mark_57", "Mark_58", "Mark_59",
"Mark_60", "Mark_61", "Mark_62", "Mark_63", "Mark_64", "Mark_65",
"Mark_66", "Mark_67", "Mark_68", "Mark_69", "Mark_70", "Mark_71",
"Mark_72", "Mark_73", "Mark_74", "Mark_75", "Mark_76", "Mark_77",
"Mark_78", "Mark_79", "Mark_80", "Mark_81", "Mark_82", "Mark_83",
"Mark_84", "Mark_85", "Mark_86", "Mark_87", "Mark_88", "Mark_89",
"Mark_90", "Mark_91", "Mark_92", "Mark_93", "Mark_94", "Mark_95",
"Mark_96", "Mark_97", "Mark_98", "Mark_99", "Mark_100", "Mark_101",
"Mark_102", "Mark_103", "Mark_104", "Mark_105", "Mark_106",
"Mark_107", "Mark_108", "Mark_109", "Mark_110", "Mark_111",
"Mark_112", "Mark_113", "Mark_114", "Mark_115", "Mark_116",
"Mark_117", "Mark_118", "Mark_119", "Mark_120", "Mark_121",
"Mark_122", "Mark_123", "Mark_124", "Mark_125", "Mark_126",
"Mark_127", "Mark_128", "Mark_129", "Mark_130", "Mark_131",
"Mark_132", "Mark_133", "Mark_134", "Mark_135", "Mark_136",
"Mark_137", "Mark_138", "Mark_139", "Mark_140", "Mark_141",
"Mark_142", "Mark_143", "Mark_144", "Mark_145", "Mark_146",
"Mark_147", "Mark_148", "Mark_149", "Mark_150", "Mark_151",
"Mark_152", "Mark_153", "Mark_154", "Mark_155", "Mark_156",
"Mark_157", "Mark_158", "Mark_159", "Mark_160", "Mark_161",
"Mark_162", "Mark_163", "Mark_164", "Mark_165", "Mark_166",
"Mark_167", "Mark_168", "Mark_169", "Mark_170", "Mark_171",
"Mark_172", "Mark_173", "Mark_174", "Mark_175", "Mark_176",
"Mark_177", "Mark_178", "Mark_179", "Mark_180", "Mark_181",
"Mark_182", "Mark_183", "Mark_184", "Mark_185", "Mark_186",
"Mark_187", "Mark_188", "Mark_189", "Mark_190", "Mark_191",
"Mark_192", "Mark_193", "Mark_194", "Mark_195", "Mark_196",
"Mark_197", "Mark_198", "Mark_199", "Mark_200", "Mark_201",
"Mark_202", "Mark_203", "Mark_204", "Mark_205", "Mark_206",
"Mark_207", "Mark_208", "Mark_209", "Mark_210", "Mark_211",
"Mark_212", "Mark_213", "Mark_214", "Mark_215", "Mark_216",
"Mark_217", "Mark_218", "Mark_219", "Mark_220", "Mark_221",
"Mark_222", "Mark_223", "Mark_224", "Mark_225", "Mark_226",
"Mark_227", "Mark_228", "Mark_229", "Mark_230", "Mark_231",
"Mark_232", "Mark_233", "Mark_234", "Mark_235", "Mark_236",
"Mark_237", "Mark_238", "Mark_239", "Mark_240", "Mark_241",
"Mark_242")), row.names = c("Mark_1", "Mark_2", "Mark_3",
"Mark_4", "Mark_5", "Mark_6", "Mark_7", "Mark_8", "Mark_9", "Mark_10",
"Mark_11", "Mark_12", "Mark_13", "Mark_14", "Mark_15", "Mark_16",
"Mark_17", "Mark_18", "Mark_19", "Mark_20", "Mark_21", "Mark_22",
"Mark_23", "Mark_24", "Mark_25", "Mark_26", "Mark_27", "Mark_28",
"Mark_29", "Mark_30", "Mark_31", "Mark_32", "Mark_33", "Mark_34",
"Mark_35", "Mark_36", "Mark_37", "Mark_38", "Mark_39", "Mark_40",
"Mark_41", "Mark_42", "Mark_43", "Mark_44", "Mark_45", "Mark_46",
"Mark_47", "Mark_48", "Mark_49", "Mark_50", "Mark_51", "Mark_52",
"Mark_53", "Mark_54", "Mark_55", "Mark_56", "Mark_57", "Mark_58",
"Mark_59", "Mark_60", "Mark_61", "Mark_62", "Mark_63", "Mark_64",
"Mark_65", "Mark_66", "Mark_67", "Mark_68", "Mark_69", "Mark_70",
"Mark_71", "Mark_72", "Mark_73", "Mark_74", "Mark_75", "Mark_76",
"Mark_77", "Mark_78", "Mark_79", "Mark_80", "Mark_81", "Mark_82",
"Mark_83", "Mark_84", "Mark_85", "Mark_86", "Mark_87", "Mark_88",
"Mark_89", "Mark_90", "Mark_91", "Mark_92", "Mark_93", "Mark_94",
"Mark_95", "Mark_96", "Mark_97", "Mark_98", "Mark_99", "Mark_100",
"Mark_101", "Mark_102", "Mark_103", "Mark_104", "Mark_105", "Mark_106",
"Mark_107", "Mark_108", "Mark_109", "Mark_110", "Mark_111", "Mark_112",
"Mark_113", "Mark_114", "Mark_115", "Mark_116", "Mark_117", "Mark_118",
"Mark_119", "Mark_120", "Mark_121", "Mark_122", "Mark_123", "Mark_124",
"Mark_125", "Mark_126", "Mark_127", "Mark_128", "Mark_129", "Mark_130",
"Mark_131", "Mark_132", "Mark_133", "Mark_134", "Mark_135", "Mark_136",
"Mark_137", "Mark_138", "Mark_139", "Mark_140", "Mark_141", "Mark_142",
"Mark_143", "Mark_144", "Mark_145", "Mark_146", "Mark_147", "Mark_148",
"Mark_149", "Mark_150", "Mark_151", "Mark_152", "Mark_153", "Mark_154",
"Mark_155", "Mark_156", "Mark_157", "Mark_158", "Mark_159", "Mark_160",
"Mark_161", "Mark_162", "Mark_163", "Mark_164", "Mark_165", "Mark_166",
"Mark_167", "Mark_168", "Mark_169", "Mark_170", "Mark_171", "Mark_172",
"Mark_173", "Mark_174", "Mark_175", "Mark_176", "Mark_177", "Mark_178",
"Mark_179", "Mark_180", "Mark_181", "Mark_182", "Mark_183", "Mark_184",
"Mark_185", "Mark_186", "Mark_187", "Mark_188", "Mark_189", "Mark_190",
"Mark_191", "Mark_192", "Mark_193", "Mark_194", "Mark_195", "Mark_196",
"Mark_197", "Mark_198", "Mark_199", "Mark_200", "Mark_201", "Mark_202",
"Mark_203", "Mark_204", "Mark_205", "Mark_206", "Mark_207", "Mark_208",
"Mark_209", "Mark_210", "Mark_211", "Mark_212", "Mark_213", "Mark_214",
"Mark_215", "Mark_216", "Mark_217", "Mark_218", "Mark_219", "Mark_220",
"Mark_221", "Mark_222", "Mark_223", "Mark_224", "Mark_225", "Mark_226",
"Mark_227", "Mark_228", "Mark_229", "Mark_230", "Mark_231", "Mark_232",
"Mark_233", "Mark_234", "Mark_235", "Mark_236", "Mark_237", "Mark_238",
"Mark_239", "Mark_240", "Mark_241", "Mark_242"), class = "data.frame")
I would like to create a nice graph (publication wise) to represent a data stored in this data frame. In general I would like to create a scatterplot or volcano plot with colors/shapes indicating what is important in my data.
I would like to achieve something like that:
Or:
As a filter cutoff we can start with: foldchange > 4 & all_pvalue < 0.05. I would like to also have a possibility to highlight (different color/shape and with a label) only couple of rows. Lets say as a starting point I would like to highlight Mark_23 and Mark_65.
Is it doable in R ? I have already tried something with volcano plot:
volcano = ggplot(data = data, aes(x = foldchange, y = -1*log10(all_pvalue)))
volcano + geom_point()
Can someone help me with going further ?
Here is an attempt to show what's possible
data$zones := interaction(abs(data$foldchange)>4,data$all_pvalue<0.05)
library(ggplot2)
library(ggrepel)
ggplot(data = data, aes(x = foldchange, y = -1*log10(all_pvalue),color = zones))+
geom_point()+
theme_light()+
geom_label_repel(aes(label=ifelse(probename %in% c("Mark_23","Mark_65"),as.character(probename),"")),
box.padding = 0.35,
point.padding = 0.5,
segment.color = 'grey50',show.legend = FALSE) +
geom_hline(yintercept = -1*log10(0.05),linetype = "dashed")+
geom_vline(xintercept = 4,linetype = "dashed")+
scale_color_manual(labels = c("bad", "also bad","good","not sure"), values = c("gray50","green","blue", "red"))+
labs(x = "fold change",
y = expression(log[10](p)),
color = "meaning")
there are many things here. geom_label_repel from library(ggrepel) allow to link your few points you want to show with a label. The easiest way of having the different colours is to create a variable that says in what zone you are. That is what I did with the zones variable, that you use in colour to have a changing color. You can manualy change it with the scale_color_manual function.
In the labs function I used the expression function that allows you to do superscripts. You can of course change the theme including, margins, axis, text size etc.
You can for example add theme(legend.position="top") to your plot to have the legend on top.

Plotting `ggplot` sorted on specific value

I have the below results and I am trying to plot using ggplot the columns using the code below but ordered such that the first ranked plot on the legend will correspond to the highest score (taken from the last row in the data). So for example the plots would be ordered in the following way, which on the legend will look like;
train_auc_9 (result = 0.9939489)
train_auc_6 (result = 0.9870544)
train_auc_3 (result = 0.9699427)
train_auc_8 (result = 0.9662169)
train_auc_7 (result = 0.9662169) etc.
Should I sort the columns based on final row value first to make life easier?
ggplot code:
ggplot(result_train_auc, aes(ID)) +
geom_line(aes(y = train_auc_1, colour = "train_auc_1")) +
geom_line(aes(y = train_auc_2, colour = "train_auc_2")) +
geom_line(aes(y = train_auc_3, colour = "train_auc_3")) +
geom_line(aes(y = train_auc_4, colour = "train_auc_4")) +
geom_line(aes(y = train_auc_5, colour = "train_auc_5")) +
geom_line(aes(y = train_auc_6, colour = "train_auc_5")) +
geom_line(aes(y = train_auc_7, colour = "train_auc_6")) +
geom_line(aes(y = train_auc_8, colour = "train_auc_7")) +
geom_line(aes(y = train_auc_8, colour = "train_auc_8")) +
geom_line(aes(y = train_auc_8, colour = "train_auc_9"))
ggtitle("auc curves") +
labs(y="auc result", x = "rounds") +
theme_bw(base_size = 11, base_family = "")
Final row of the data.
0.9177697
0.9309705
0.9699427
0.9431463
0.9544374
0.9870544
0.9538312
0.9662169
0.9939489
100
data called result_train_auc.
structure(list(train_auc_1 = c(0.8713344, 0.8871179, 0.8928057,
0.8964518, 0.8976864, 0.8995532, 0.9001708, 0.9015733, 0.9022265,
0.9027288, 0.9031676, 0.9036361, 0.9040329, 0.9045184, 0.9048802,
0.9053402, 0.9055032, 0.9056735, 0.9061118, 0.9062926, 0.9064719,
0.9067036, 0.9069563, 0.9071833, 0.9074455, 0.907724, 0.907817,
0.9081296, 0.9082689, 0.9084679, 0.9086163, 0.9087718, 0.9091238,
0.9093731, 0.9095402, 0.909702, 0.909771, 0.9099373, 0.9101334,
0.9103078, 0.9104885, 0.9106456, 0.9107819, 0.9108925, 0.9111391,
0.9112471, 0.9114579, 0.9115598, 0.9116752, 0.9117411, 0.9118367,
0.9120177, 0.9121465, 0.9123075, 0.9125142, 0.9125989, 0.9127896,
0.9128665, 0.9129764, 0.9130837, 0.9132152, 0.9133399, 0.9135001,
0.9136408, 0.9137385, 0.9138751, 0.9139981, 0.9140897, 0.914189,
0.9142859, 0.9144037, 0.9145455, 0.9146629, 0.9147381, 0.9148613,
0.9149902, 0.9150876, 0.9151985, 0.9153009, 0.9154068, 0.915529,
0.9156637, 0.9157626, 0.9158646, 0.915995, 0.9161135, 0.9162173,
0.9163324, 0.91642, 0.9165297, 0.9166981, 0.9168092, 0.9169468,
0.9170768, 0.9171896, 0.9173152, 0.9174244, 0.9175383, 0.9176803,
0.9177697), train_auc_2 = c(0.8870459, 0.9021414, 0.9085472,
0.9114717, 0.9136837, 0.9148831, 0.9160633, 0.916577, 0.9175609,
0.918181, 0.9185195, 0.9189418, 0.919285, 0.9195346, 0.9197795,
0.9201756, 0.9205287, 0.9207205, 0.9208646, 0.9210185, 0.9211867,
0.9213273, 0.9214634, 0.9217073, 0.921851, 0.9220127, 0.9221905,
0.9224531, 0.9227193, 0.9228104, 0.9229566, 0.9231306, 0.9233425,
0.9234565, 0.9235739, 0.9237399, 0.9239113, 0.9240052, 0.9242447,
0.9243938, 0.9245815, 0.9247349, 0.92491, 0.9250047, 0.9251303,
0.9252628, 0.925474, 0.9256335, 0.9257628, 0.9258756, 0.9259525,
0.9260501, 0.9261603, 0.9262516, 0.926404, 0.9264811, 0.9266122,
0.9267074, 0.9268346, 0.9269162, 0.9270102, 0.9271369, 0.9272119,
0.9273092, 0.9274163, 0.9275176, 0.9276396, 0.9277829, 0.9278664,
0.927978, 0.928066, 0.9281753, 0.9283186, 0.928417, 0.9285194,
0.9286077, 0.9286985, 0.9287818, 0.9288713, 0.9289982, 0.9290624,
0.9291517, 0.929267, 0.9293397, 0.9294468, 0.9295616, 0.9296748,
0.9297741, 0.9298962, 0.929982, 0.9300875, 0.9301889, 0.9302799,
0.9303726, 0.9304612, 0.930582, 0.9306869, 0.9307636, 0.9308679,
0.9309705), train_auc_3 = c(0.920364, 0.9396713, 0.9477804, 0.9511932,
0.9533659, 0.9548309, 0.9560987, 0.9569889, 0.9577224, 0.9580906,
0.9585115, 0.9590348, 0.9592664, 0.9596969, 0.9600961, 0.9603775,
0.9605959, 0.9608837, 0.9611088, 0.9612673, 0.9614595, 0.9616898,
0.9618144, 0.961986, 0.9621864, 0.9623498, 0.9624878, 0.9626525,
0.9627835, 0.9628886, 0.9629866, 0.9631557, 0.9632875, 0.9634212,
0.9635417, 0.9636695, 0.9637814, 0.9638905, 0.9639689, 0.9640757,
0.964196, 0.9643034, 0.9644215, 0.9645278, 0.9646416, 0.9647334,
0.9648655, 0.9649719, 0.9650779, 0.9651884, 0.9653068, 0.9654192,
0.9655179, 0.9656188, 0.9657627, 0.965861, 0.9659789, 0.966077,
0.9661733, 0.966301, 0.9664198, 0.9664838, 0.9665656, 0.9666834,
0.9667807, 0.9668807, 0.9669509, 0.9670521, 0.9671343, 0.9672346,
0.967336, 0.9674322, 0.9675225, 0.9676096, 0.9677119, 0.9678031,
0.967893, 0.9679848, 0.9680899, 0.968179, 0.9682643, 0.9683379,
0.9684383, 0.9685187, 0.9686161, 0.9687164, 0.9688037, 0.9688999,
0.9689951, 0.9690893, 0.9691872, 0.9692667, 0.9693624, 0.9694321,
0.9695126, 0.9695981, 0.9696739, 0.9697611, 0.9698583, 0.9699427
), train_auc_4 = c(0.8719551, 0.8896184, 0.8948779, 0.898766,
0.9027315, 0.9049762, 0.9062427, 0.9073199, 0.9081683, 0.9092019,
0.9100824, 0.9109981, 0.9116318, 0.9123474, 0.9131612, 0.9138763,
0.9145007, 0.9152897, 0.9158685, 0.9166697, 0.9172174, 0.9179825,
0.9186526, 0.9193314, 0.9199804, 0.9205763, 0.9212371, 0.921792,
0.9223935, 0.9229936, 0.9234932, 0.9240162, 0.9245426, 0.9250783,
0.9256483, 0.9262044, 0.9267231, 0.9271653, 0.9276435, 0.9280976,
0.9284953, 0.9289266, 0.9293313, 0.9297668, 0.9301079, 0.9305796,
0.9309791, 0.9314001, 0.9317514, 0.932084, 0.9323953, 0.9326925,
0.9330121, 0.933329, 0.9335974, 0.9339083, 0.934189, 0.9344819,
0.934775, 0.9350779, 0.9353696, 0.9356319, 0.9358907, 0.9361598,
0.9364136, 0.936647, 0.9368967, 0.9370801, 0.9373547, 0.9375985,
0.9378257, 0.9380637, 0.9382862, 0.9385131, 0.9387194, 0.9389419,
0.9391624, 0.9393709, 0.939553, 0.9397668, 0.9399806, 0.9401861,
0.9403382, 0.9404968, 0.9406843, 0.9408617, 0.9410371, 0.9412126,
0.9413865, 0.9415654, 0.9417246, 0.9418873, 0.9420531, 0.9422337,
0.9423998, 0.9425335, 0.9426956, 0.9428642, 0.9429921, 0.9431463
), train_auc_5 = c(0.8894875, 0.9047447, 0.9105668, 0.9144695,
0.9172043, 0.9185459, 0.919896, 0.9209646, 0.9220889, 0.9229307,
0.923797, 0.9245408, 0.9252745, 0.9258488, 0.9264725, 0.9270811,
0.927705, 0.9283463, 0.9288456, 0.9293815, 0.9299636, 0.9305526,
0.9311112, 0.9317484, 0.9323305, 0.9328307, 0.9332667, 0.9338263,
0.9343498, 0.9348398, 0.9353667, 0.9358599, 0.9362733, 0.9367398,
0.9371676, 0.9376035, 0.9380137, 0.93843, 0.9388201, 0.9392386,
0.9396649, 0.9400335, 0.940358, 0.940702, 0.9410648, 0.9414072,
0.9417623, 0.9421251, 0.9424502, 0.9428179, 0.9431571, 0.9434742,
0.9438279, 0.9441624, 0.9444683, 0.944784, 0.9450568, 0.9453451,
0.9456379, 0.9459065, 0.9462062, 0.9464493, 0.9467355, 0.9469841,
0.9472465, 0.9475116, 0.9477762, 0.948027, 0.9482639, 0.9485123,
0.9487707, 0.9489929, 0.9492213, 0.9494459, 0.9497089, 0.9499556,
0.9501546, 0.9503753, 0.9505703, 0.9507616, 0.9509694, 0.9511743,
0.9513489, 0.9515396, 0.9517049, 0.9518854, 0.9520863, 0.9522618,
0.9524513, 0.9526601, 0.9528238, 0.9530262, 0.953238, 0.9534353,
0.9535989, 0.9537715, 0.953945, 0.9541034, 0.9542643, 0.9544374
), train_auc_6 = c(0.921898, 0.9414678, 0.9480329, 0.9519876,
0.9548386, 0.9567495, 0.9580347, 0.959306, 0.9603841, 0.9614684,
0.9623793, 0.9630147, 0.9637751, 0.964326, 0.9648042, 0.9653413,
0.9658432, 0.9664368, 0.9670508, 0.9675288, 0.9681021, 0.9685874,
0.969052, 0.9695682, 0.9699854, 0.9704805, 0.9708863, 0.97131,
0.9717166, 0.9721004, 0.9724803, 0.9728962, 0.9732809, 0.9736517,
0.9740503, 0.9744405, 0.974781, 0.9751438, 0.9754958, 0.9758019,
0.9761391, 0.9764902, 0.9768141, 0.9771417, 0.9774458, 0.9777964,
0.9780874, 0.9783719, 0.9786893, 0.9789502, 0.9792233, 0.9794795,
0.979716, 0.9799766, 0.9802053, 0.9804437, 0.9806533, 0.9808698,
0.9810933, 0.9813374, 0.9815627, 0.9817506, 0.9819429, 0.9821263,
0.9823146, 0.9824981, 0.9826867, 0.9828871, 0.9830589, 0.9832092,
0.9833926, 0.983539, 0.983694, 0.9838324, 0.9839557, 0.9841259,
0.9843032, 0.9844521, 0.9845934, 0.9847127, 0.9848563, 0.9849894,
0.9851023, 0.9852643, 0.9853757, 0.9854869, 0.9856046, 0.9857333,
0.9858394, 0.9859424, 0.9860531, 0.9861587, 0.986294, 0.9864175,
0.9865295, 0.9866261, 0.9867294, 0.986843, 0.9869372, 0.9870544
), train_auc_7 = c(0.8714998, 0.8904612, 0.8996561, 0.9041253,
0.9066398, 0.9086743, 0.910345, 0.9116165, 0.9130665, 0.914957,
0.9166201, 0.9180005, 0.9195517, 0.9207296, 0.9218763, 0.9230211,
0.9241087, 0.9252396, 0.9262592, 0.9271692, 0.9280938, 0.9289803,
0.9297884, 0.9305648, 0.9311738, 0.9317921, 0.9323804, 0.9329845,
0.933683, 0.9341942, 0.9347607, 0.9352553, 0.9357764, 0.9363214,
0.9367976, 0.9372965, 0.9377839, 0.9382045, 0.9386436, 0.9391153,
0.939509, 0.9399301, 0.9402878, 0.9405964, 0.9409411, 0.9413296,
0.9416693, 0.9419742, 0.9423106, 0.9426316, 0.9428824, 0.94322,
0.9435017, 0.9438152, 0.9440885, 0.9443691, 0.9446256, 0.9449214,
0.9451091, 0.945326, 0.9456083, 0.9458252, 0.9460603, 0.94633,
0.946581, 0.9468279, 0.9470671, 0.9473089, 0.9474984, 0.9477469,
0.9479721, 0.9482038, 0.9484291, 0.9486507, 0.9488756, 0.9490827,
0.9492949, 0.9494745, 0.9497085, 0.9499118, 0.9501382, 0.9503468,
0.9505637, 0.9507583, 0.9509843, 0.9512342, 0.9514627, 0.9516457,
0.9518377, 0.9520731, 0.9522473, 0.9524432, 0.9526339, 0.9528058,
0.9529749, 0.9531575, 0.9533158, 0.953497, 0.953663, 0.9538312
), train_auc_8 = c(0.8894918, 0.906573, 0.9133049, 0.9168864,
0.9194233, 0.9219299, 0.9237789, 0.9252068, 0.9265656, 0.9281103,
0.929274, 0.9307909, 0.9317895, 0.9328411, 0.933978, 0.9349498,
0.9358906, 0.936782, 0.9376891, 0.9385461, 0.9393091, 0.9401118,
0.940883, 0.941568, 0.9421953, 0.9427495, 0.9434112, 0.9439894,
0.944666, 0.9452999, 0.9457854, 0.9463698, 0.9468706, 0.9473643,
0.947829, 0.9482811, 0.9487576, 0.9492046, 0.9496415, 0.9500149,
0.9504884, 0.9509045, 0.9512969, 0.951719, 0.95214, 0.9525265,
0.9528557, 0.9531854, 0.9535102, 0.9537721, 0.9541137, 0.9544496,
0.9548184, 0.9551027, 0.955434, 0.9557073, 0.955989, 0.9563086,
0.9565974, 0.9569073, 0.9571664, 0.9574366, 0.9577329, 0.9580357,
0.9582985, 0.9585633, 0.9587903, 0.9590735, 0.9593316, 0.9596137,
0.9598677, 0.9600993, 0.9602947, 0.9605253, 0.9607954, 0.9610258,
0.9612257, 0.9614929, 0.9617122, 0.9619397, 0.9622056, 0.9624263,
0.9626628, 0.9628691, 0.9631282, 0.9633603, 0.9635655, 0.9638023,
0.9640161, 0.9642836, 0.9644966, 0.9646435, 0.9648045, 0.964987,
0.9652297, 0.9654192, 0.9655976, 0.9657743, 0.965976, 0.9662169
), train_auc_9 = c(0.9195993, 0.9417172, 0.949147, 0.9537538,
0.9565765, 0.9589093, 0.9607099, 0.962332, 0.9639256, 0.9652906,
0.9664848, 0.9675891, 0.9685598, 0.9695702, 0.9705377, 0.9713772,
0.9722889, 0.9730441, 0.9738743, 0.9745701, 0.9752537, 0.9759395,
0.9765657, 0.9772191, 0.9778215, 0.9783909, 0.9789667, 0.979504,
0.9799884, 0.9804533, 0.9808872, 0.9813206, 0.981738, 0.982081,
0.9824229, 0.9827401, 0.983044, 0.9833385, 0.9836874, 0.9840525,
0.9843545, 0.9845821, 0.984868, 0.985124, 0.9853725, 0.9855741,
0.9857704, 0.9860043, 0.986215, 0.9864325, 0.9865974, 0.9867876,
0.9870471, 0.9872346, 0.987455, 0.9877028, 0.9879157, 0.9880718,
0.9882622, 0.9884967, 0.9886666, 0.9888404, 0.9890087, 0.9891979,
0.9893628, 0.9895276, 0.9896856, 0.989821, 0.9899959, 0.9901792,
0.9903423, 0.9905105, 0.9906635, 0.9908151, 0.99095, 0.991091,
0.9912231, 0.9913755, 0.9914875, 0.9916226, 0.991765, 0.9919017,
0.9920161, 0.9921698, 0.9923023, 0.9924097, 0.9925314, 0.9926483,
0.9927896, 0.992922, 0.9930381, 0.9931279, 0.9932223, 0.9933255,
0.9934563, 0.99354, 0.9936327, 0.9937486, 0.9938403, 0.9939489
), ID = 1:100), .Names = c("train_auc_1", "train_auc_2", "train_auc_3",
"train_auc_4", "train_auc_5", "train_auc_6", "train_auc_7", "train_auc_8",
"train_auc_9", "ID"), row.names = c(NA, -100L), class = "data.frame")
EDIT: Added a picture for clarification.
Here is a way to do it. Notice that I reshape the data to use full power of plotting aesthetics:
library(tidyr)
library(ggplot2)
# reshape the data
df %>%
gather(trainauc, value, -ID) -> df
# get the order
df %>%
filter(ID == 100) %>%
arrange(desc(value)) %>%
.$trainauc -> leg_order
# plot
ggplot(df, aes(ID)) +
geom_line(aes(y = value, colour = trainauc)) +
scale_colour_discrete(breaks = leg_order) +
labs(title = "auc curves", y = "auc result", x = "rounds") +
theme_bw(base_size = 11, base_family = "") +

Plotting Curves from Data Frame Columns

i am facing a problem in plot ols estimations in a scatterplot:
I have this data frame: With 9 columns and 99 rows:
structure(list(Y = c(-0.145442175, 0.291096141, 0.489923112,
-2.038363166, 1.180430664, 0.188114666, 0.850922634, 1.172142766,
-3.980837975, 0.285762444, 2.497040646, 0.658010994, -0.925171981,
0.37076995, -1.108211119, -0.409242669, -1.234583525, -0.385841816,
0.016744771, -0.584406288, 1.17224811, -0.746804388, -0.625028046,
0.257871468, -2.735845346, 2.619304857, -0.406825232, 0.323665151,
2.218951363, -0.821029648, -0.872854889, -2.663306158, -0.121976044,
0.881566376, -1.972706678, -3.855576256, 2.927421113, 1.314753531,
0.234296206, 0.828464757, -0.909318569, 0.616134903, -0.567630403,
0.624571064, -0.414112923, 0.642200314, -0.309421266, 0.195312598,
-0.519988256, 0, 0.081070175, 0.032446432, -0.534025032, -0.426783307,
-0.38495511, -0.207900219, -1.953789746, -0.616924355, -0.783222881,
-1.935420969, 0.638445535, 1.080925923, -1.598076681, 0.25063631,
-0.697183766, 0.188971653, -0.415267389, -4.154506044, 1.163226552,
0.036569698, -0.547147074, 1.11937374, 0.383311682, -0.875037781,
-0.372684863, 0.306816004, -1.250561544, -1.042237738, -1.757788446,
0.021079982, 1.844023775, 1.674645753, -0.428546132, -0.527705597,
0.542202572, -0.621479123, -0.050415867, -0.122332943, 0.468553764,
0.216998274, 3.088480781, 0.434099931, 2.114916704, -2.407018936,
-0.127060127, 0.546756422, 0.263207486, 0.63453915, 0.76832746
), X = c(0.009476137, -0.0236354, 0.0094081, 0.11715252, 0.032324021,
0.0461193, 0.050794971, 0.032372819, 0.202121874, 0.390821859,
-0.124492596, -0.127305193, -0.22233597, -0.081113713, 0.09952616,
0.22494711, 0.226621495, 0.411607624, 0.089200478, -0.013454832,
-0.013547165, -0.232366214, 0.03140992, -0.026798837, -0.084556341,
-0.091993172, -0.303730207, -0.236679148, -0.284235285, -0.355253166,
-0.179645537, -0.01381843, -0.022950244, -0.050065976, -0.032018504,
-0.087168055, -0.081865767, -0.253991077, -0.242882759, -0.150225053,
-0.16596575, -0.156887247, -0.071795146, -0.100408802, -0.067307731,
0.024006869, -0.019250912, -0.02399429, 0.038421097, 0.062320065,
0.07187025, 0.024019462, 0.038421097, 0.033539309, 0.014351457,
-0.009575137, 0.014343968, 0.028561284, 0.0404213, 0.026065697,
-0.004700435, -0.072739794, -0.042217496, -0.05889531, -0.130522139,
-0.136291869, -0.120099035, -0.091418565, -0.122040844, -0.124609029,
-0.096255449, -0.190338762, -0.11611752, -0.055598423, -0.065293448,
-0.038746326, -0.029090518, -0.067627348, -0.082097445, -0.215845836,
-0.389993696, -0.264371785, -0.126530291, -0.111840985, -0.094952196,
-0.136700196, -0.190968195, -0.156564122, -0.181077278, -0.15381292,
-0.122020692, -0.107867301, -0.068642333, -0.034348677, -0.073289926,
-0.063314884, -0.092537576, -0.165375956, -0.15042398), Null = c(-0.036795117836493,
0.0120555676565338, -0.0366906491623935, -0.22323992930528, -0.0728300398338213,
-0.0955073599141197, -0.103350601084975, -0.0729090354522075,
-0.400153521158964, -0.887015257107641, 0.1362666683468, 0.13919994231771,
0.221388292373518, 0.087380368104602, -0.189831042487278, -0.452154909992189,
-0.456044210600938, -0.948567833126862, -0.170785020294756, -0.00253939338337472,
-0.00240533038312774, 0.228145471304061, -0.0713518661553421,
0.0165138860659871, 0.0915102566139487, 0.100284493544177, 0.265652059802101,
0.230938443729295, 0.257246215885006, 0.281209408151878, 0.188533028671265,
-0.00201164134414489, 0.0110851592192505, 0.0481858583559124,
0.0237904823161768, 0.094614581053392, 0.0882862377341187, 0.241468070168396,
0.234837060900023, 0.162029971029324, 0.176601607696189, 0.168307425791361,
0.0759851164110966, 0.109970788582389, 0.0703849242291975, -0.059492586621119,
0.00581616568295407, 0.0125631925046972, -0.0827672867080164,
-0.123023227393077, -0.139691063870559, -0.0595125909296922,
-0.0827672867080164, -0.074799966578053, -0.044324863847201,
-0.00820062690976645, -0.0443132308515717, -0.0667648997869916,
-0.0860567642206439, -0.0627706942069095, -0.0153914247452083,
0.0771546773236518, 0.0377224646820258, 0.0596889425617937, 0.1425196179012,
0.148379247725525, 0.13162698340227, 0.0996137276510431, 0.133686233062275,
0.136388667637584, 0.105222539655097, 0.197385328960716, 0.127361748973716,
0.0554268640818151, 0.0678473149754353, 0.0330232883757411, 0.0197208677278167,
0.0707862239701058, 0.0885648870712001, 0.216820906265572, 0.286245951224793,
0.247258814186372, 0.138394666330137, 0.122716205945161, 0.103719679674083,
0.148789344619283, 0.197893429730301, 0.168006688568371, 0.189742414352596,
0.165430712615822, 0.133664933948451, 0.11833998959919, 0.0720581343490991,
0.0270069004188009, 0.077834296346802, 0.0653403280475977, 0.100918894574441,
0.176071877748707, 0.162219750035618), OLS_1 = c(-2.97674658085357,
-2.95792547866683, -2.97674412477729, -2.7937460366665, -2.96913739819288,
-2.95639989365184, -2.95069150171007, -2.96910314906723, -2.3856485268894,
-0.647452287114872, -2.68293610049662, -2.670570393744, -2.10297963546522,
-2.84137496711892, -2.84927190111917, -2.23638642750757, -2.22477621905134,
-0.385841816000001, -2.87715002139054, -2.96747293407547, -2.96740133507642,
-2.02609643038743, -2.9697648045679, -2.95427875550959, -2.8310157181346,
-2.80733412921436, -1.38551048535346, -1.99204069101103, -1.57679230211392,
-0.821029648, -2.39395151432173, -2.96718943992586, -2.95867282134313,
-2.9175506236826, -2.94755679517459, -2.82290206987746, -2.83914454134393,
-1.84931168689084, -1.94200482386918, -2.56030139156351, -2.4747687889082,
-2.52507434784403, -2.86749990988846, -2.77838660436577, -2.87908253396987,
-2.97385415360498, -2.96244666805069, -2.95752797222193, -2.96426392038595,
-2.93361303993881, -2.91621877029975, -2.97384869333029, -2.96426392038595,
-2.96826157356433, -2.97653443074828, -2.97023260580068, -2.97653534550966,
-2.9715473503959, -2.96240424133875, -2.97289412424858, -2.9730125951007,
-2.86497897723402, -2.93188917574701, -2.89904800305061, -2.6561144854951,
-2.62935195635151, -2.70174255054932, -2.80922741244202, -2.69350740105694,
-2.68242924921473, -2.79295820376613, -2.32657978700299, -2.718248099245,
-2.90625073580661, -2.88407071600265, -2.93759776247538, -2.95143559806685,
-2.87827902655775, -2.83845377816351, -2.15100018436527, -0.392139380784325,
-1.7590965971582, -2.67400272569948, -2.73540774982849, -2.79741598960129,
-2.62741730304073, -2.322499279269, -2.52681590220219, -2.38514457172383,
-2.541507865502, -2.6935934995898, -2.75082409521646, -2.87570553083222,
-2.94427256930162, -2.86349763526591, -2.88884317216564, -2.80553055841713,
-2.47811758528604, -2.55927025907886), OLS_2 = c(-2.83865555876367,
-2.82203271957637, -2.83865550287755, -2.66277932892391, -2.83073328950317,
-2.8182826854432, -2.81275284604234, -2.83069942358793, -2.27571536741022,
-0.632851535784811, -2.56646067709365, -2.55491098827374, -2.02364579120999,
-2.71420058960775, -2.71564453925406, -2.13442002502496, -2.12343285482248,
-0.385841816, -2.74223576659719, -2.83068449367348, -2.83062014186059,
-1.95158880862936, -2.83135434505306, -2.81870405841395, -2.70456098525177,
-2.68251016192609, -1.35080974869909, -1.91966655284606, -1.53026524143009,
-0.821029648, -2.29619548286091, -2.83042962848176, -2.82271365766308,
-2.78489427206998, -2.81254809712918, -2.69700817487578, -2.71212546804251,
-1.78585373408616, -1.87276085874404, -2.45184700668681, -2.37183555552258,
-2.41889982491589, -2.73848954857785, -2.65553364194069, -2.74924637290594,
-2.8354502300085, -2.82614423798244, -2.82167034953476, -2.82594242161564,
-2.7962902949221, -2.77959589724382, -2.83544467118397, -2.82594242161564,
-2.82986834510621, -2.83829410413293, -2.83315419155684, -2.83829521382395,
-2.83312719078141, -2.82412509152621, -2.83447802392599, -2.83561001727694,
-2.73614728712302, -2.79813447119318, -2.76776591170989, -2.54140667394362,
-2.5163996858597, -2.58402223424852, -2.68427373122372, -2.57633280462435,
-2.56598731123967, -2.66911582708562, -2.23311605677819, -2.59943103595799,
-2.7744383205277, -2.75387620457868, -2.80339428073398, -2.81610308322424,
-2.74850042856033, -2.71148276169435, -2.06864445166113, -0.418358709691658,
-1.7012556906544, -2.558117011201, -2.61544592452239, -2.67326984561107,
-2.5145916492569, -2.22929491666958, -2.42052887445801, -2.28795076147412,
-2.43427089501948, -2.57641320261571, -2.62982944259216, -2.74611100908034,
-2.80953310903525, -2.73477077084888, -2.75830410348864, -2.68083005992821,
-2.37496906485549, -2.4508827380889), OLS_3 = c(-2.58083646581942,
-2.5683178338716, -2.58084089114316, -2.41826149362172, -2.57232965672457,
-2.56041470241702, -2.55521822468909, -2.57229650627193, -2.0704676472292,
-0.605591599496051, -2.34899840070827, -2.33897223601076, -1.87552769159633,
-2.47676312148376, -2.46615920192222, -1.94404642215785, -1.9342224786085,
-0.385841816000001, -2.49034777076914, -2.57529735049815, -2.57524652934739,
-1.81248137667339, -2.57293885513887, -2.56558300171966, -2.46846711008925,
-2.44946096338359, -1.28602268062379, -1.78454238349805, -1.4433981562183,
-0.821029648, -2.11368273887782, -2.57509593622485, -2.56887479307252,
-2.53722183306237, -2.56048377359198, -2.46196139684977, -2.47497795642607,
-1.66737628649693, -1.7434807939705, -2.24936019247138, -2.17965685727221,
-2.22066956504207, -2.49762425675709, -2.42616435450559, -2.50683929408026,
-2.57704694280319, -2.57166448720316, -2.56802106429762, -2.56769302344379,
-2.53990559282486, -2.52451787208599, -2.57704119998386, -2.56769302344379,
-2.57148502596854, -2.58019625622877, -2.57722566059429, -2.58019772985789,
-2.57469359055957, -2.56595475982599, -2.57605200249485, -2.57907626550515,
-2.49561557851369, -2.54841138215235, -2.52265924802504, -2.32724456926626,
-2.30551521644622, -2.36423571438323, -2.45098235381054, -2.35756515622,
-2.3485875529132, -2.43789928063234, -2.05861713726078, -2.37759686441414,
-2.52834152993493, -2.51080007744427, -2.55283331443161, -2.56343418632904,
-2.50620082129485, -2.47442497328161, -1.91488441727801, -0.467310795744689,
-1.59326539683083, -2.34175573481226, -2.39147445613669, -2.44148615865099,
-2.30394357612981, -2.05528024243402, -2.22208856552246, -2.10648769733616,
-2.23405702128991, -2.35763491117015, -2.40392966200837, -2.50415507637054,
-2.55797145858227, -2.49443477420494, -2.51458468009137, -2.44801138045477,
-2.18238842077399, -2.24852076027753), OLS_4 = c(-2.4289478285331,
-2.41681903415288, -2.42895104301202, -2.27867081965274, -2.4213161496905,
-2.41038194422522, -2.40559515788832, -2.42128586809391, -1.95522949388955,
-0.590647453749078, -2.21077815389366, -2.20138321248198, -1.76758669368012,
-2.33060054299992, -2.32313500877883, -1.83755181381677, -1.82840597739465,
-0.385841816, -2.34557046847711, -2.42346978407977, -2.42342111188123,
-1.70861264386732, -2.42187239429871, -2.41422413566286, -2.32281181955877,
-2.30497392699143, -1.21632553238408, -1.68248005204524, -1.36346128591018,
-0.781669317752002, -1.99042352676657, -2.42327691796255, -2.41734804581689,
-2.38744248609079, -2.40939495374384, -2.31670510436427, -2.32892438647688,
-1.57289978140148, -1.64407512538075, -2.11744278294415, -2.05217911016675,
-2.09057710272701, -2.35019495754122, -2.28311871426765, -2.35885543710246,
-2.42560672084754, -2.42000135641999, -2.4165372393818, -2.41707097497419,
-2.39145946177805, -2.3772271125231, -2.42560153071694, -2.41707097497419,
-2.420544236609, -2.42841594588832, -2.4253216199613, -2.42841722040367,
-2.42347169955882, -2.41547562547196, -2.42470587973943, -2.4271143253132,
-2.34830761179908, -2.39799094116799, -2.37373288731684, -2.19039487337143,
-2.17003793409615, -2.22505776553193, -2.30640152341961, -2.21880622042115,
-2.21039315621698, -2.294126428977, -1.93888869626962, -2.23758086989921,
-2.37908034073483, -2.36257901260101, -2.4021644964107, -2.41218787827608,
-2.35825527028976, -2.3284051877118, -1.80440438182757, -0.451087514089169,
-1.50359480720157, -2.20399138892979, -2.25058992243427, -2.29749148286179,
-2.16856567860513, -1.93576601076367, -2.09190575790345, -1.98368936201681,
-2.10311255036163, -2.21887159162467, -2.26226743315126, -2.35633238493592,
-2.407018936, -2.34719820268328, -2.36613768370737, -2.30361375259329,
-2.05473632620086, -2.11665669129059), OLS_5 = c(-2.2911912568638,
-2.28123967681215, -2.29119683586224, -2.14805590207021, -2.28325670505768,
-2.27261386268403, -2.268006850245, -2.28322682471889, -1.84560662105751,
-0.576090713535621, -2.0945064647732, -2.0859234999636, -1.68828464788266,
-2.20368547406672, -2.18986194988925, -1.73587625378362, -1.72735189094969,
-0.385841816, -2.21101101562234, -2.28700200417098, -2.28696051646281,
-1.63411554699496, -2.28380625780731, -2.27896044246845, -2.19661244829441,
-2.18039652225164, -1.18146437845759, -1.6101070827248, -1.31682391434599,
-0.781364138557704, -1.89278224977018, -2.28683751979873, -2.28170279433502,
-2.25507742887343, -2.27469315563211, -2.19106352335337, -2.20216376634672,
-1.50940418054145, -1.57481865165838, -2.00915316980509, -1.94938461398854,
-1.98455653642811, -2.22145418758665, -2.1605019074557, -2.22929361026136,
-2.28754415075922, -2.28401553991566, -2.28099274980288, -2.2790962708342,
-2.25448944582185, -2.24095826297856, -2.28753886744317, -2.2790962708342,
-2.28249611688223, -2.29051254450738, -2.28856644852124, -2.29051401027405,
-2.28539476406181, -2.27754391464367, -2.28663199585719, -2.29003809100396,
-2.21974449731936, -2.26453458741267, -2.24273365564754, -2.0758820670505,
-2.05727208640147, -2.1075473897372, -2.18169509790509, -2.10183883759691,
-2.0941547862828, -2.17052540371127, -1.84552009498619, -2.11897925887711,
-2.2475539961602, -2.23266092019845, -2.26826235385205, -2.27716458812284,
-2.22875067319638, -2.20169236013157, -1.72209385129724, -0.476893951190187,
-1.44569200778405, -2.08830648613957, -2.13084935049209, -2.17358829667077,
-2.05592583172644, -1.84265559786228, -1.98577321824112, -1.88660772323127,
-1.99603456442263, -2.10189853669134, -2.14149931364702, -2.22701080101746,
-2.27258448425562, -2.21873931960315, -2.23587705524471, -2.17915915787995,
-1.95172754860073, -2.00843362344438), OLS_6 = c(-2.14615029819501,
-2.1274826763545, -2.14613692884822, -2.038363166, -2.14482079785526,
-2.13839956793073, -2.1352633011825, -2.14480554064275, -1.77137087834078,
-0.604458131512312, -1.92044345866761, -1.91142894340333, -1.5035051350835,
-2.03720410348948, -2.07364942604987, -1.67230210256299, -1.66457879312031,
-0.427523081653794, -2.09111249534671, -2.1358169999572, -2.13575175544593,
-1.44873737433719, -2.14509683128765, -2.12442374236989, -2.02946586195686,
-2.01185030632841, -0.994510606111227, -1.42450007218492, -1.12983335353955,
-0.596198212559954, -1.7115906309286, -2.13555900800151, -2.12811588444992,
-2.09509015766854, -2.11889016916752, -2.02341958358771, -2.03553614239934,
-1.32305159796573, -1.38891263096519, -1.83141440901763, -1.76969899713653,
-1.80596583024281, -2.05682837956465, -1.99043348930533, -2.06558998487816,
-2.14664801486533, -2.13135448546891, -2.1271468279034, -2.14250449627423,
-2.12545741758249, -2.11509475538252, -2.1466464083569, -2.14250449627423,
-2.14442504670383, -2.14684049810003, -2.13838680613343, -2.1468398441846,
-2.14583791450693, -2.14156460788614, -2.14633891192499, -2.14114136796206,
-2.05492693125432, -2.10632999229998, -2.08080895764288, -1.90090288083161,
-1.88144765246016, -1.93417313784094, -2.01325520240903, -1.9281579797124,
-1.92007377040746, -2.00120005643771, -1.66327168223962, -1.94624457366434,
-2.08634430885867, -2.06937728900294, -2.11086434271986, -2.12206882778948,
-2.06498074945642, -2.03501978622706, -1.5377512452434, -0.29431817292714,
-1.25902518147068, -1.91393009686737, -1.95881793980313, -2.00449939786682,
-1.88004274517372, -1.66034827254381, -1.80722288608151, -1.70526848086161,
-1.81783189921089, -1.92822084254891, -1.97013652098612, -2.0630309651189,
-2.1162243283256, -2.0538104595074, -2.07300962091288, -2.0105124912345,
-1.7721107506457, -1.83066883021211)), .Names = c("Y", "X", "Null",
"OLS_1", "OLS_2", "OLS_3", "OLS_4", "OLS_5", "OLS_6"), row.names = c(NA,
99L), class = "data.frame")
My scatter plot will consist of the first column (Y) and the second column (X).
The third column i will not use.
From the fourth column are the curves that are fitted values of OLS regressions.
How do I include them using the plot function?
i am doing this, but its not working
plot(data[,2],data[,1])
for(i in 4:9){
lines(data[,i])
}
What am i doing wrong?
Basically you want
data <- data[order(data$X), ] ## reordering so that `X` is increasing
plot(data$X, data$Y)
for (i in 4:9) {
lines(data$X, data[,i], col = i) ## remember to set `x-coordinates`
}
legend("topright", legend = names(data)[4:9], col = 4:9, lty = 1) ## add legend

Resources