0

I am new to R. I have a data frame which a part looks like this. (The original data size is 20 x 50)

I need to make a plot with all the V1~V20 columns in X axis. I am expecting a simple line plot, like this (without legends).

I've tried to implement answers from similar questions on the site but I couldn't make them work.

Any help will be very appreciated! Thank you in advance.

EDIT: I tried using dput() to copy my data (sorry it's long), hope it helps making my question understandable.

structure(c(2.99982, 3.999675, 3.33302, 3.24972, 2.799696, 2.49968, 
2.571129, 2.624715, 2.666393, 2.699736, 2.908808, 3.166378, 3.845871, 
3.714002, 3.466402, 3.249752, 3.35268, 3.277515, 3.315537, 3.249746, 
3.380693, 3.317921, 3.347573, 3.333084, 3.279749, 3.268982, 3.184931, 
3.142602, 3.206634, 3.166403, 3.128768, 3.124738, 3.151259, 3.146805, 
3.114031, 3.055297, 3.107844, 3.026058, 2.999742, 2.974741, 2.95096, 
2.952123, 2.97649, 2.954291, 2.955303, 2.934529, 2.935918, 2.937249, 
2.979337, 3.039743, 1.99971, 2.99982, 2.33308, 2.249738, 2.199732, 
2.33308, 2.571201, 2.624779, 2.88864, 2.799747, 2.999727, 2.916393, 
2.768947, 2.785438, 2.79973, 2.999724, 3.11736, 3.055268, 2.947075, 
2.999718, 2.999723, 2.954268, 2.869282, 2.999714, 2.959714, 2.884325, 
2.851561, 2.856856, 2.930741, 3.066375, 3.031966, 3.062215, 3.030018, 
2.999715, 3.028293, 3.083049, 3.05377, 3.05235, 3.051003, 3.124719, 
3.146066, 3.094959, 3.092747, 3.090635, 3.066392, 3.064945, 3.084838, 
3.041396, 3.020137, 3.01973, 0, 0.999855, 2.66645, 2.749792, 
2.799798, 2.833135, 2.856947, 2.499829, 2.777573, 2.599776, 2.727063, 
2.749793, 3.076712, 3.356929, 3.199774, 3.062263, 2.99976, 3.055325, 
2.999766, 2.949764, 3.047371, 3.09067, 3.173663, 3.083078, 2.999738, 
2.961276, 2.962703, 3.071165, 3.068705, 3.166403, 3.193291, 3.218498, 
3.181565, 3.08799, 3.114045, 3.027544, 3.026795, 3.052404, 3.025412, 
2.974766, 2.950984, 2.952147, 3.023019, 3.09067, 3.088651, 3.08672, 
3.169976, 3.124759, 3.101799, 3.09976, 1.999965, 2.999973, 3.333309, 
3.499977, 3.399976, 2.999973, 3.142831, 2.874972, 3.222197, 3.499977, 
3.545432, 3.333309, 3.076901, 3.071406, 2.999976, 2.874975, 2.705859, 
2.777755, 2.947346, 3.049979, 3.142836, 3.136342, 3.086935, 3.166645, 
3.159978, 3.115362, 3.148126, 3.10712, 3.103426, 3.166644, 3.12901, 
3.093727, 3.060583, 2.970565, 2.999977, 2.972199, 2.918895, 2.868397, 
2.871771, 2.899976, 2.829245, 2.83331, 2.953465, 2.931794, 2.911087, 
2.89128, 2.914869, 2.895809, 2.857118, 2.879975, 2.999973, 1.499986, 
1.666646, 2.499982, 2.799982, 2.666645, 2.714264, 2.499975, 2.333307, 
2.499974, 2.454519, 2.249975, 2.461515, 2.642835, 2.599977, 2.624976, 
2.647035, 2.777755, 2.842082, 2.949978, 2.952358, 2.909068, 2.826063, 
2.749975, 2.799975, 2.769206, 2.740715, 2.821404, 2.827561, 2.933309, 
3.032235, 2.968726, 2.969673, 2.970564, 2.942833, 2.972198, 2.918894, 
2.894712, 2.871769, 2.824974, 2.829242, 2.880927, 2.883695, 2.931793, 
2.999975, 3.043454, 3.042529, 3.062476, 3.122425, 3.099976, 6.99975, 
6.99975, 6.66638, 6.249668, 5.399676, 4.66633, 4.285384, 4.249703, 
4.333017, 4.199697, 4.181536, 4.249703, 4.230489, 4.49973, 4.46641, 
4.312241, 4.17621, 4.277512, 4.36815, 4.299734, 4.333057, 4.226996, 
4.260584, 4.249724, 4.239732, 4.268955, 4.184909, 4.106866, 3.999719, 
4.066383, 3.999716, 3.968469, 3.999714, 3.970305, 3.914002, 3.860827, 
3.837557, 3.947091, 3.922802, 3.899728, 3.853386, 3.904487, 3.929953, 
3.863354, 3.910827, 3.869281, 3.850782, 3.853889, 3.836459, 3.859721, 
3.99993, 3.499875, 2.99982, 3.499748, 3.19974, 2.999735, 3.14262, 
2.874743, 3.11083, 2.999718, 2.727016, 2.583065, 2.384368, 2.428329, 
2.399754, 2.499765, 2.41152, 2.33308, 2.262897, 2.249738, 2.33308, 
2.272467, 2.391035, 2.416401, 2.359729, 2.307417, 2.407124, 2.606865, 
2.654902, 2.766393, 2.83843, 2.81222, 2.908808, 2.88207, 2.999718, 
2.97194, 3.0808, 3.05235, 3.025359, 2.999718, 3.024113, 3.047347, 
3.022983, 2.999727, 2.977505, 2.97799, 2.935896, 2.874732, 2.897695, 
2.899738, 3.999981, 3.999981, 3.333309, 3.499977, 3.199975, 3.666645, 
3.428548, 3.499977, 3.555533, 3.19998, 3.090887, 2.999977, 2.84613, 
3.142831, 3.133307, 3.249975, 3.411741, 3.388865, 3.368397, 3.299975, 
3.23807, 3.181793, 3.304323, 3.249975, 3.239975, 3.307668, 3.259234, 
3.178546, 3.172388, 3.099974, 3.161265, 3.156224, 3.151489, 3.147033, 
3.142831, 3.194419, 3.216191, 3.289449, 3.333309, 3.349976, 3.317049, 
3.380928, 3.348813, 3.318157, 3.333309, 3.326063, 3.361678, 3.312475, 
3.28569, 3.339976, 1.999965, 2.999973, 3.999981, 4.249983, 4.399984, 
4.499985, 4.428556, 4.249983, 4.111093, 3.999981, 3.818161, 3.583311, 
3.538439, 3.78569, 3.866643, 3.687475, 3.647034, 3.55553, 3.52629, 
3.499974, 3.333309, 3.272702, 3.304323, 3.291642, 3.199975, 3.230744, 
3.111087, 3.142833, 3.03446, 3.066644, 3.096751, 3.124977, 3.151492, 
3.117624, 3.085691, 2.999977, 2.97295, 2.947345, 2.897412, 2.899976, 
2.853634, 2.833309, 2.860441, 2.863612, 2.888864, 2.86954, 2.872316, 
2.895809, 2.938751, 2.899975, 0.999957, 1.499961, 2.999973, 2.499969, 
2.59997, 3.166641, 3.28569, 3.249975, 3.444421, 3.499977, 3.545432, 
3.499977, 3.461515, 3.428548, 3.599978, 3.624978, 3.470565, 3.555533, 
3.473661, 3.499977, 3.428548, 3.590885, 3.521714, 3.541642, 3.559975, 
3.461513, 3.703679, 3.642832, 3.655147, 3.733309, 3.645136, 3.624975, 
3.606035, 3.558798, 3.485688, 3.444418, 3.378352, 3.368394, 3.384589, 
3.399974, 3.390218, 3.357116, 3.372067, 3.386337, 3.377752, 3.3478, 
3.319122, 3.29164, 3.265279, 3.319974, 2.999973, 2.499969, 1.999965, 
2.499969, 2.59997, 2.666637, 2.999973, 2.624976, 2.888867, 2.799976, 
2.636338, 2.583307, 2.461511, 2.357114, 2.399972, 2.499972, 2.411736, 
2.444416, 2.526288, 2.449971, 2.428542, 2.499971, 2.608668, 2.624972, 
2.799971, 2.846126, 2.777749, 2.785686, 2.758592, 2.766638, 2.87094, 
2.812472, 2.818153, 2.823501, 2.857115, 2.916639, 2.864837, 2.947341, 
2.897408, 2.924972, 2.951192, 2.976163, 2.90695, 2.863609, 2.844417, 
2.934755, 3.042525, 3.104139, 3.14283, 3.119973, 1.999965, 3.499977, 
3.999981, 3.249975, 2.59998, 2.833313, 2.714264, 2.999979, 3.333315, 
3.499982, 3.454527, 3.416647, 3.230748, 3.071406, 3.133311, 3.124977, 
3.117624, 3.055532, 3.10524, 3.099976, 3.047595, 3.13634, 3.043454, 
2.999975, 3.119976, 3.230746, 3.296274, 3.321406, 3.379288, 3.399978, 
3.451591, 3.374978, 3.42422, 3.441154, 3.485693, 3.499978, 3.459438, 
3.473662, 3.461516, 3.399977, 3.414612, 3.35712, 3.348814, 3.409068, 
3.377755, 3.347803, 3.425508, 3.374976, 3.346915, 3.339976, 4.999989, 
2.499995, 2.333318, 2.999986, 2.799982, 3.666645, 3.999981, 3.999981, 
3.999981, 3.999981, 4.545435, 4.333313, 4.153824, 4.285694, 4.333314, 
4.31248, 4.294098, 4.333314, 4.263138, 4.14998, 3.952362, 3.999981, 
3.913024, 3.833313, 3.87998, 3.76921, 3.666645, 3.67855, 3.551703, 
3.566646, 3.516108, 3.468728, 3.42422, 3.411742, 3.399978, 3.4722, 
3.405383, 3.499977, 3.512798, 3.549977, 3.512172, 3.476167, 3.441837, 
3.38634, 3.333309, 3.282584, 3.297848, 3.249975, 3.265281, 3.239975, 
1.999965, 2.499969, 2.999973, 2.499969, 2.399968, 2.166633, 2.142823, 
2.249967, 2.222189, 2.299967, 2.181785, 2.083299, 2.230736, 2.285682, 
2.666634, 2.812468, 2.882322, 2.833302, 2.842074, 2.799969, 2.904732, 
2.863606, 2.826056, 2.791636, 2.67997, 2.615355, 2.6296, 2.642827, 
2.655143, 2.699971, 2.709648, 2.624972, 2.696942, 2.676442, 2.685686, 
2.749972, 2.675649, 2.631552, 2.640998, 2.624973, 2.829241, 2.880926, 
2.860438, 2.818155, 2.822195, 2.847799, 2.851037, 2.895807, 2.918341, 
2.859974, 5.999997, 3.499977, 3.666645, 2.999973, 2.999973, 3.166641, 
3.28569, 3.374976, 3.222197, 3.099974, 2.818158, 2.833309, 2.84613, 
2.785689, 2.799975, 2.812475, 2.941152, 2.888864, 2.789448, 2.849974, 
2.857117, 2.727248, 2.826063, 2.874976, 2.879976, 2.923053, 2.999977, 
2.964262, 2.965493, 3.03331, 3.032235, 3.031226, 2.939371, 2.941153, 
2.971406, 2.999977, 2.97295, 3.236818, 3.230745, 3.299977, 3.34144, 
3.33331, 3.325558, 3.295431, 3.288865, 3.282585, 3.340402, 3.374977, 
3.428549, 3.479978, 6.999954, 3.999955, 4.666636, 4.749974, 4.999979, 
4.499976, 4.142832, 3.624978, 3.333309, 3.599978, 3.727252, 3.499977, 
3.84613, 3.714261, 3.599974, 3.499974, 3.470562, 3.444418, 3.52629, 
3.599975, 3.619023, 3.54543, 3.39128, 3.374976, 3.279975, 3.192282, 
3.07405, 3.107119, 3.137907, 3.133309, 3.129008, 3.124976, 3.121188, 
3.029388, 3.057119, 2.999976, 3.027003, 3.026292, 3.025617, 3.049976, 
2.999975, 3.047595, 3.092999, 3.159067, 3.155532, 3.130411, 3.127636, 
3.166643, 3.122425, 3.079976, 0.999957, 0.999957, 1.333293, 1.249959, 
1.39996, 1.833297, 2.285682, 2.499969, 2.666637, 2.699971, 2.545424, 
2.499969, 2.999969, 3.071398, 3.066637, 3.06247, 3.058794, 3.055526, 
2.947338, 3.049971, 3.285685, 3.409063, 3.347797, 3.416639, 3.359972, 
3.307664, 3.296268, 3.357115, 3.275834, 3.299972, 3.322553, 3.374973, 
3.363609, 3.352914, 3.371402, 3.333306, 3.270243, 3.315762, 3.256383, 
3.224972, 3.146314, 3.16664, 3.162764, 3.204519, 3.266641, 3.260844, 
3.234016, 3.187473, 3.163239, 3.159973, 2.999973, 3.999981, 2.999973, 
3.499977, 3.799979, 3.333309, 3.142831, 2.999973, 3.444415, 3.199969, 
3.090878, 2.916635, 2.692278, 2.499973, 2.466639, 2.499972, 2.47056, 
2.499972, 2.473656, 2.549972, 2.666639, 2.909063, 2.869537, 2.999973, 
3.039973, 3.115359, 3.074048, 3.035688, 3.034456, 3.099974, 3.096748, 
3.093724, 3.030276, 2.999973, 2.971401, 2.944417, 2.945919, 2.947341, 
2.897408, 2.949973, 2.951192, 2.880926, 2.883694, 2.999973, 3.022195, 
3.021712, 2.999973, 2.999973, 2.979565, 3.019973, 0.999957, 2.999973, 
3.666645, 3.499977, 3.399976, 2.833313, 2.857122, 2.874978, 2.999979, 
2.999978, 2.999978, 3.083311, 2.923053, 2.928547, 3.066644, 2.937476, 
2.823504, 2.888864, 2.894712, 2.899975, 2.904737, 2.909066, 2.869539, 
2.916641, 3.039975, 2.999975, 2.9259, 2.928546, 2.999975, 2.933308, 
3.096748, 3.093724, 3.121186, 3.058797, 2.999973, 2.999973, 3.027, 
3.078921, 3.076897, 3.074974, 3.073144, 3.047592, 3.069741, 3.090883, 
3.044418, 3.043452, 3.042527, 3.062473, 3.102015, 3.059973, 6.999954, 
4.49996, 4.3333, 3.249975, 2.799971, 2.666637, 2.571398, 2.499969, 
2.666637, 2.499969, 2.727244, 2.916639, 2.769202, 2.857115, 2.866639, 
2.999973, 2.999973, 3.222194, 3.157866, 3.049971, 3.04759, 2.999971, 
3.086928, 2.999971, 2.999971, 2.961509, 2.925896, 2.999971, 2.965488, 
2.966638, 3.03223, 3.031222, 2.969668, 2.999971, 3.028543, 3.13886, 
3.081052, 3.078918, 3.051253, 3.024971, 3.024361, 3.02378, 2.999971, 
3.022698, 3.022193, 3.02171, 3.042524, 2.999971, 3.040788, 3.039971), .Dim = c(50L, 20L))
  • Welcome to Stack Overflow, and R! It is common practice to share a [minimal reproducible code example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) which highlights your question. – shayaa Jul 27 '16 at 15:08
  • @shayaa Thank you for the tips! It's my first time asking a question here. I've edited my question. – user6645351 Jul 27 '16 at 15:34
  • I don't think that data you have posted is a data frame or matrix. It appears to be a vector. I will try to help you anyways. – shayaa Jul 27 '16 at 15:39
  • Could you elaborate the desired output ? What do you want in x and y axis more precisely ? – bVa Jul 27 '16 at 15:56

1 Answers1

0

Suppose you had random walks in each column of the data and you wanted to plot them on the same plot. The base plotting function matplot allows you to do this easily.

First create the data

mat <- matrix(sample(c(1,-1),1000, replace  = T), nrow = 100,10)
df <- data.frame(1:100, mat)

Then cumulatively sum each column to produce a simple random walk

df[,2:11] <- apply(df[,2:11], 2, cumsum)
names(df) <- c("index", paste0("Var",1:10))

Then plot it with a legend. df[,-1] tells you to exclude the index variable from the matplot.

 matplot(df[1], df[,-1], type="l",
           xlab = "index", lty = 1)
legend("right", legend = names(df)[-1], inset= .01)

enter image description here

There are many other ways to visualize the columns of the data, this is just one.

shayaa
  • 2,787
  • 13
  • 19