2

I have the following values:

Day 1: X11 X12 X13 X14 X15 ...
Day 2: X21 X22 X23 X24 X25 ...
Day 3: X31 X32 X33 X34 X35 ...
...
...

I can use the values of each day to plot a different CDF but is there a way I can visualize CDFs for all days to see how the distribution is changing across time? Is there something like a 3D variant that I can plot?

Actual values:

structure(list(Time = structure(c(1354348800, 1354435200, 1354521600, 
1354608000, 1354694400, 1354780800, 1354867200, 1354953600, 1355040000, 
1355126400, 1355212800, 1355299200, 1355385600, 1355472000, 1355558400, 
1355644800, 1355731200, 1355817600, 1355904000, 1355990400, 1356076800, 
1356163200, 1356249600, 1356336000, 1356422400, 1356508800, 1356595200, 
1356681600, 1356768000, 1356854400, 1356940800, 1354348800, 1354435200, 
1354521600, 1354608000, 1354694400, 1354780800, 1354867200, 1354953600, 
1355040000, 1355126400, 1355212800, 1355299200, 1355385600, 1355472000, 
1355558400, 1355644800, 1355731200, 1355817600, 1355904000, 1355990400, 
1356076800, 1356163200, 1356249600, 1356336000, 1356422400, 1356508800, 
1356595200, 1356681600, 1356768000, 1356854400, 1356940800, 1354348800, 
1354435200, 1354521600, 1354608000, 1354694400, 1354780800, 1354867200, 
1354953600, 1355040000, 1355126400, 1355212800, 1355299200, 1355385600, 
1355472000, 1355558400, 1355644800, 1355731200, 1355817600, 1355904000, 
1355990400, 1356076800, 1356163200, 1356249600, 1356336000, 1356422400, 
1356508800, 1356595200, 1356681600, 1356768000, 1356854400, 1356940800, 
1354348800, 1354435200, 1354521600, 1354608000, 1354694400, 1354780800, 
1354867200, 1354953600, 1355040000, 1355126400, 1355212800, 1355299200, 
1355385600, 1355472000, 1355558400, 1355644800, 1355731200, 1355817600, 
1355904000, 1355990400, 1356076800, 1356163200, 1356249600, 1356336000, 
1356422400, 1356508800, 1356595200, 1356681600, 1356768000, 1356854400, 
1356940800, 1354348800, 1354435200, 1354521600, 1354608000, 1354694400, 
1354780800, 1354867200, 1354953600, 1355040000, 1355126400, 1355212800, 
1355299200, 1355385600, 1355472000, 1355558400, 1355644800, 1355731200, 
1355817600, 1355904000, 1355990400, 1356076800, 1356163200, 1356249600, 
1356336000, 1356422400, 1356508800, 1356595200, 1356681600, 1356768000, 
1356854400, 1356940800, 1354348800, 1354435200, 1354521600, 1354608000, 
1354694400, 1354780800, 1354867200, 1354953600, 1355040000, 1355126400, 
1355212800, 1355299200, 1355385600, 1355472000, 1355558400, 1355644800, 
1355731200, 1355817600, 1355904000, 1355990400, 1356076800, 1356163200, 
1356249600, 1356336000, 1356422400, 1356508800, 1356595200, 1356681600, 
1356768000, 1356854400, 1356940800), class = c("POSIXct", "POSIXt"
), tzone = ""), Value = c(430664.239261698, 490234.194921927, 
526998.520971122, 536602.462982633, 258691.669906957, 11829.8290116318, 
12650.9461086689, 2720.1227453922, 6148.95630258592, 2680.86993550808, 
2678.03258008561, 2665.03710105507, 2704.83781604574, 2704.99305811391, 
2742.7040489269, 2802.16126409598, 2835.37392203882, 2822.02107441536, 
2816.32800725421, 2798.97376034702, 2796.01930330326, 2754.58930695667, 
2745.58482436398, 2729.8646537471, 2706.30089379909, 2657.97901504968, 
2755.8939918735, 2756.32635948648, 2703.73644754399, 2595.09862261747, 
2583.96164402217, 1103.38595759987, 1410.11179619836, 4758.52642632149, 
4799.73333750023, 3881.64395298922, 2769.52071665839, 2777.36511823707, 
2728.37598724549, 2732.36209370411, 2695.9513678436, 2686.83499265917, 
2681.5743717285, 2720.45290857566, 2732.73841594837, 2760.53934947503, 
2811.42766223853, 2844.41105991693, 2825.55269421361, 2820.7691523964, 
2807.55312109634, 2804.11955879203, 2757.32663905538, 2745.86930679521, 
2739.23425025641, 2715.98260303707, 2692.68857278371, 3527.71521116871, 
4262.25327731706, 4533.9804534, 4481.65508241964, 4421.37186792114, 
19613453.922832, 124804222.41819, 141787648.586654, 130924910.79881, 
168814882.872211, 11894959.6456705, 8774239.566537, 16080698.3234849, 
17161993.52566, 22336448.9385156, 15252276.6007502, 10331573.337916, 
8976597.77324162, 17169136.7951364, 12183504.3046438, 6957562.92857611, 
12930867.2067763, 10663528.8499475, 8969032.06072141, 12857780.0335602, 
10766886.886599, 14795620.653363, 9825272.66156014, 11044813.0699568, 
10367171.6540806, 9610185.60847421, 10931660.4285495, 8394075.58812457, 
8993089.38056002, 8026650.35585018, 7946595.12661373, 114329906.004844, 
137475638.687273, 148815385.289035, 135307862.23453, 184737114.110537, 
119730959.539068, 69757385.6095225, 90614972.0916845, 86831718.3941103, 
119775130.022637, 88442212.7020717, 58451067.337829, 65388376.2367906, 
63443348.7417144, 57280954.523376, 45166897.0970657, 83554097.8501678, 
66201693.7873501, 70795197.9863679, 84221546.3400137, 72983744.7919536, 
79897785.2230573, 69847018.9176478, 73346675.6554418, 64914201.3793851, 
63947528.2287373, 65351437.5297966, 59076239.7375999, 42688084.2661814, 
42066287.169797, 39734565.1701957, 90506964.9337797, 100149152.452364, 
120257643.646244, 111528999.398328, 138621214.049053, 9371.8136697, 
56524340.9066957, 73183012.7386646, 73134499.5072141, 91844218.5996012, 
59462704.401716, 46340856.9647138, 49809994.4841905, 52046927.2065564, 
43534299.417627, 37959416.2194319, 64876408.0181902, 55169784.3656278, 
55637721.2148036, 64303390.999086, 55469744.4302739, 59472270.8402672, 
52495047.7346662, 59934890.0182395, 57773465.6418628, 57227960.3434529, 
58180354.3542921, 50719237.2638962, 33168848.2017861, 33850765.333152, 
33841026.2326982, 110504056.059923, 133797335.531811, 148626502.57032, 
130569007.27317, 163603482.922618, 110945447.425452, 67150219.14672, 
85584433.1881761, 76873561.2170393, 117860559.12102, 84629012.3662336, 
54204572.2980234, 58898821.9609343, 62180038.7679437, 53059333.3332883, 
43914570.1205393, 79475697.2825237, 64196704.372024, 66182175.1487631, 
80851142.6092836, 65475805.206847, 68931230.2593625, 59859872.3417313, 
65228418.926433, 61498299.9737327, 60767088.8695188, 62752189.9148476, 
56770234.222601, 40910036.2385198, 39235601.7774785, 37635952.1705463
)), .Names = c("Time", "Value"), row.names = c(NA, -186L), class = "data.frame")

EDIT: Resulting image

enter image description here

Legend
  • 113,822
  • 119
  • 272
  • 400

1 Answers1

5

Sure. Check function rgl.surface() in package rgl:

library(rgl)
data <- lapply(seq(0,2,by=0.1),function(i){rnorm(100)+i})  # a list with example data vectors
m <- sapply(data,function(i){ecdf(i)(seq(-3,5,by=0.1))})   # a matrix with the empirical CDF for each vector in the list, over a given range -3 to 5
rgl.surface(1:nrow(m), 5*(1:ncol(m)), m*20)    # play with the coefficients to get a better result

You can even rotate this surface! For more, check this question.

UPDATE: Here's what you can do with your data:

values.per.day <- lapply(unique(data$Time), function(x)data$Value[data$Time==x])
m <- sapply(values.per.day, function(x) ecdf(x)(seq(min(data$Value), max(data$Value), length.out=1000)) )
rgl.surface(1:nrow(m), 5*(1:ncol(m)), m*20)
Community
  • 1
  • 1
Theodore Lytras
  • 3,955
  • 1
  • 18
  • 25
  • +1 Thank you very much. I read the documentation for rgl but am not able to find out if it is possible to 1. Draw coordinate axes and 2. Export to png/eps. Can you give me some pointers on how to achieve this? Thanks! – Legend Jan 08 '13 at 23:27
  • Sure. Check `?axis3d`, `?rgl.snapshot` and `?rgl.postscript` in package `rgl`. – Theodore Lytras Jan 08 '13 at 23:36
  • I have a quick request. While your example of creating a matrix makes perfect sense, I am not quite sure how to do the same for my data. I have a data frame with date as one column and value as another column. The idea is to compute the CDF per day and then plot it in 3d using time as the third dimension. I have been trying to use `ddply` but I don't understand how to format this data properly. Can you kindly help me? I updated my question with the datastructure. – Legend Jan 09 '13 at 01:15
  • This is awesome. As a final request, would you mind explaining what the last step is doing? I understand the first two but what are `5` and `20` multiplicative factors in the last step? Because, in the obtained graph, I don't see how to read my original values from the temporal ecdf plot. – Legend Jan 09 '13 at 17:07
  • Check the arguments for `rgl.surface()`. The third argument, `m`, is a matrix of heights, and the first two are the x and y coordinates for each height. `5` and `20` are arbitrary coefficients to "spread along" the surface, for clarity. – Theodore Lytras Jan 09 '13 at 18:01
  • I see. Thank you. I was confused because when I used rgl::axes3D(), it gives me the index for the data point I'm assuming rather than the actual value. Updated my question to show this. – Legend Jan 09 '13 at 18:20