Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have the following data:

data = {{0, 0}, {20, 1.4}, {25, 9.8}, {30, 32.2}, {35, 38.2}, {40, 15.6}, {45, 2.7}, {50, 0.1}};

where the second coordinates are frequencies measured as percent of total (adding, therefore, to $100$). I would like to produce a cumulative frequency plot. What would be the neatest way to do so?

share|improve this question
3  
I'm not sure whether you're correct describing your data as frequencies. I'm assuming you're using this phrase in a statistical context, meaning counts and not a physical context (in Hertz). Given you have cumulative frequency I suppose it's the former, but then how can you have non-integer values? –  Sjoerd C. de Vries Mar 10 '13 at 21:37
    
I meant accumulative. I was looking for the answer you gave me below, thanks! –  Frederik Brinck Jensen Mar 11 '13 at 7:10
    
I didn't say "cumulative" was wrong. I just made a remark about the values not being integer. I now assume they are relative frequencies and that therefore there's no reason for the term 'Total' in my answer (it does no harm either). –  Sjoerd C. de Vries Mar 11 '13 at 9:08
    
I didn't get that they were relative frequencies, however seems that you're right about that! –  Frederik Brinck Jensen Mar 11 '13 at 12:50
    
There still remain questions of the meaning and interpretation of these data, Frederik. E.g., does the appearance of {{0,0}, {20,1.4}, ...} mean that $1.4$% of the frequency lies within the interval $[0,20]$ or that $1.4$% lies *exactly* at $20$? Should the plot reflect the data accurately or--as suggested by the accepted answer--attempt to interpolate between the bin cutpoints? Evidently the interpolation must be monotonic, but should it necessarily be linear (as in the accepted answer)? –  whuber Mar 11 '13 at 17:20

2 Answers 2

up vote 10 down vote accepted
ListLinePlot[{data[[All, 1]], Accumulate[#]/Total[#] &@data[[All, 2]]}\[Transpose]]

Mathematica graphics

share|improve this answer
    
you probably meant Accumulate...data[[All,2]]? –  kguler Mar 11 '13 at 3:56
    
@kguler yeah, will correct figure when I'm near mma. Thanks. –  Sjoerd C. de Vries Mar 11 '13 at 6:35
1  
Terse style (in the FrontEnd): ListLinePlot[{#, Accumulate@#/Tr@# &@#2}\[Transpose]] & @@ (data\[Transpose]) –  Mr.Wizard Mar 11 '13 at 8:08

You can transform the data as follows, and then plot transdata,

transdata = Partition[Riffle[data[[All, 1]], Accumulate@data[[All, 2]]], 2]

Surely this is a neat way, but it remains to be seen if its the neatest.

share|improve this answer
    
Also # ~Riffle~ Accumulate[#2] ~Partition~ 2 & @@ Transpose[data], though I would use data[[All, 2]] = Accumulate @ data[[All, 2]]; data :-) –  Mr.Wizard Mar 11 '13 at 3:34
2  
also, transdata = Transpose[{data[[All, 1]], Accumulate@data[[All, 2]]}] –  Iiss Mar 11 '13 at 4:35
1  
Yes. This one looks good in the FrontEnd: {#, Accumulate@#2}\[Transpose] & @@ (data\[Transpose]) (By the way the only reason I haven't voted for this answer is that I honestly don't understand the question.) –  Mr.Wizard Mar 11 '13 at 4:59
    
@Mr.Wizard I have performed a somewhat aggressive edit of the question to reflect an interpretation suggested by the accepted answer. –  whuber Mar 11 '13 at 17:17

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.