# Compute the evolution of percentages from a data file

My data is stored in external .out files which contain six columns and a large number of rows. I know that I have to provide a small sample but the structure of my data is so unique, so I provide the entire data file here: data

This time we need only columns 1, 2 and 6. The first column contains the x position, second column the corresponding energy E, while the six column has only integers regarding a classification. Now if we plot in a 2D diagram the first two columns assigning in every point a color according the value of the six column we get the following

Now I want to do the following. For every value of E we have several values of x with different classification. The possible integers of the sixth column are: {-1, 1, 2, 11, 12, 21, 22, 31, 32, 99}. I want to compute how many -1, 1, 2, ..., 99 are for the first value of E and compute the corresponding percentages. Then go to the next value of E and repeat the procedure. Thus we can follow the evolution of percentages as a function of E. The ultimate goal is to create a diagram showing all together with the corresponding colors the 10 trend lines.

Any suggestions on how to achieve this?

And here is a small data sample as minimal working example

{{-5., -3, 24.89,
0.8079019748736321, -1, -1}, {-4.977477477477477, -3, 24.72,
0.8100409238103935, -1, 1}, {-4.954954954954955, -3, 24.54,
0.8122953345427153, -1, 2}, {-4.932432432432432, -3, 24.36,
0.8145539903185015, -1, 21}, {-4.90990990990991, -3, 24.19,
0.8167060089472148, -1, -1}, {-4.887387387387387, -3, 24.01,
0.8189737833735357, -1, -1}, {-4.864864864864865, -3, 23.84,
0.8211357279224385, -1, -1}, {-4.842342342342342, -3, 23.67,
0.823303331789986, -1, 99}, {-4.81981981981982, -2, 23.5,
0.8254770541856945, -1, -1}, {-4.797297297297297, -2, 23.32,
0.8277682452908253, -1, 32}, {-4.774774774774775, -2, 23.15,
0.8299553813547601, -1, 21}, {-4.752252252252252, -2, 22.98,
0.8321495854317591, -1, 11}, {-4.72972972972973, -2, 22.82,
0.8342399060011664, -1, -1}, {-4.707207207207207, -2, 22.65,
0.8364482241698246, -1, 2}, {-4.684684684684685, -2, 22.48,
0.8386633336338121, -1, -1}, {-4.662162162162162, -1, 22.31,
0.8408848961319084, -1, 22}, {-4.63963963963964, -1, 22.15,
0.843001699453557, -1, 12}, {-4.617117117117117, -1, 21.98,
0.8452350102456677, -1, 1}, {-4.594594594594595, -1, 21.81,
0.8474735570160751, -1, 2}, {-4.572072072072072, -1, 21.65,
0.8496066341065539, -1, 11}, {-4.54954954954955, -1, 21.49,
0.8517447815274005, -1, 32}, {-4.527027027027027, 0, 21.32,
0.8539977804973352, -1, -1}, {-4.504504504504505, 0, 21.16,
0.8561457246831677, -1, 2}, {-4.481981981981982, 0, 21.,
0.8582989136727225, -1, 1}, {-4.45945945945946, 0, 20.83,
0.8605668266689402, -1, 11}, {-4.436936936936937, 0, 20.67,
0.862731269804195, -1, -21}, {-4.414414414414415, 1, 20.51,
0.8649021245634532, -1, 22}, {-4.391891891891892, 1, 20.35,
0.8670798666925034, -1, -1}, {-4.36936936936937, 1, 20.19,
0.8692649521543424, -1, 2}, {-4.346846846846847, 1, 20.03,
0.8714577803779188, -1, 1}, {-4.324324324324325, 1, 19.88,
0.873550635695638, -1, 32}, {-4.301801801801802, 1, 19.72,
0.8757599471643019, -1, 99}, {-4.27927927927928, 1, 19.56,
0.8779776273998509, -1, 11}}


something like this:

 p[list_] := (#/Total[#]) &@(Count[list, #] & /@ {-1, 1, 2, 11, 12, 21,22, 31, 32, 99} );
x = {#[[1, 2]], p@ #[[All, 6]]} & /@ GatherBy[ data ,  #[[2]] & ];

ListPlot[ Table[ {#[[1]], #[[2, i]]} & /@ x , {i, 1, 10}] , Joined -> True]


somewhat cleaner alternate form:

p[list_] := #/Total[#] &@
BinCounts[ list, { {-1, 1, 2, 11, 12, 21, 22, 31, 32, 99, Infinity} }];

• I think this is exactly what I what. Just a minor comment. Now the percentage is expressed in decimal between [0, 1]. How can I change it to % between [0, 100]? Commented Jan 9, 2015 at 15:44
• just put 100 in here: (100 #/Total[#])` Commented Jan 9, 2015 at 15:47
• Many many thanks! Commented Jan 9, 2015 at 15:49