6
$\begingroup$

INSEE the french economic statistic provider gives the data to construct an age pyramid as follow --- the data has been extracted with mathematica

for males

m=  {375301., 386444., 388571., 395224., 399798., 411273., 409974., 
    411160., 409128., 416521., 407867., 405266., 402933., 406016., 
    412048., 421114., 404408., 399542., 389842., 387386., 377748., 
    361790., 355598., 372001., 373723., 378834., 376348., 379519., 
    380054., 384618., 384804., 381879., 379210., 404101., 407789., 
    414886., 392867., 387833., 392934., 383131., 393548., 418549., 
    440843., 452887., 448856., 439785., 430238., 424829., 422819., 
    433382., 434562., 437581., 432484., 416168., 415676., 413461., 
    409280., 399063., 395888., 389819., 383308., 383795., 372386., 
    377394., 366631., 381169., 370698., 370458., 359965., 338567., 
    252587., 243895., 234663., 215924., 188793., 193056., 197482., 
    189589., 179984., 174402., 163136., 157720., 142724., 139104., 
    125494., 114298., 96198., 84893., 71483., 60336., 49822., 39524., 
    31336., 24670., 18835., 13864., 5876., 3507., 1946., 1260., 1130., 
    968., 488., 350., 231., 179.}

for females

 f= {358397., 369044., 370305., 374957., 382669., 391063., 389825., 
   392278., 390713., 396610., 388589., 386924., 384382., 386032., 
   393155., 401263., 382722., 381673., 370414., 370901., 364179., 
   350937., 348432., 365904., 372969., 380064., 383041., 388514., 
   388991., 398308., 396483., 398032., 391630., 417629., 423251., 
   426437., 403575., 395808., 397809., 388493., 399157., 420531., 
   444918., 455485., 452475., 443853., 438708., 436616., 433360., 
   443394., 445043., 452670., 447656., 431500., 433817., 431185., 
   431045., 421231., 421791., 419369., 415861., 415005., 406147., 
   413990., 403282., 418967., 412927., 409442., 400765., 381494., 
   287013., 281008., 272477., 251224., 226014., 236255., 247953., 
   243974., 239400., 238560., 233509., 233675., 220211., 221785., 
   207813., 199911., 177746., 162828., 147133., 132731., 118113., 
   99694., 84923., 71615., 57824., 45756., 20755., 13293., 9197., 6124., 
   4666., 5124., 3040., 1790., 1239., 1464.}

and of course for the labels

 `l = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 14., 
 15., 16., 17., 18., 19., 20., 21., 22., 23., 24., 25., 26., 27., 28., 
 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 40., 41., 42., 
 43., 44., 45., 46., 47., 48., 49., 50., 51., 52., 53., 54., 55., 56., 
 57., 58., 59., 60., 61., 62., 63., 64., 65., 66., 67., 68., 69., 70., 
 71., 72., 73., 74., 75., 76., 77., 78., 79., 80., 81., 82., 83., 84., 
 85., 86., 87., 88., 89., 90., 91., 92., 93., 94., 95., 96., 97., 98., 
 99., 100., 101., 102., 103., 104., 105 ou plus}` 

PairedBarChart[h1, f1]

gives

enter image description here

There are many problems

1) the result is unreadable due to the overcrowding of bins.

2) I was unable to transform the label in the good format which must be of the type {"a", "b", "c"} --- so how to add "" to a list of data ( I know I must transform initialy an expression in string but nothing I tried haw worked.

3) how to agregate data say 5 by 5 the the last entry managed differently to obtain a age pyramid of the type 1-5, 6-10... more than

( Incidently I think that one of the big problems of the documentation of Mathematica in what concerns statistics is to postulate taht data come within Mathematica itself )

Ps I am always late to help other because I have no warning for new questions. Is there a way to have an alert when a question arrive.

$\endgroup$
7
$\begingroup$

Something like

PairedBarChart[
 Append[Total /@ Partition[Most[f], 5], Last[f]],
 Append[Total /@ Partition[Most[m], 5], Last[m]],
 ChartLabels -> Append[StringTemplate["``-``"][5 (# - 1), 5 (# - 1) + 4] & /@ Range[21], "105 ou plus"],
 BarSpacing -> {1.5 10^6, Automatic, Automatic}
 ]

Mathematica graphics

To convert your list of labels to strings you could have used ToString /@ l.

|improve this answer|||||
$\endgroup$
  • $\begingroup$ very nice partitioning and labeling using StringTemplate (something to add to my 'useful things'pile). :) $\endgroup$ – ubpdqn Aug 30 '16 at 7:19
4
$\begingroup$

This is a hack but perhaps it can be modified as required:

df[lst_, val_] := 
 Catenate@MapThread[Table[#2, Round[#1/1000]] &, {lst, val}]
male = df[m, lab];
female = df[f, lab];
PairedHistogram[male, female, Automatic, "Count", 
 AxesLabel -> {"x 1000 count", "Age(years)"}, 
 ChartStyle -> {{LightRed, LightBlue}}, 
 ChartLegends -> {"Female", "Male"}]

enter image description here

Data:

m = {375301., 386444., 388571., 395224., 399798., 411273., 409974., 
   411160., 409128., 416521., 407867., 405266., 402933., 406016., 
   412048., 421114., 404408., 399542., 389842., 387386., 377748., 
   361790., 355598., 372001., 373723., 378834., 376348., 379519., 
   380054., 384618., 384804., 381879., 379210., 404101., 407789., 
   414886., 392867., 387833., 392934., 383131., 393548., 418549., 
   440843., 452887., 448856., 439785., 430238., 424829., 422819., 
   433382., 434562., 437581., 432484., 416168., 415676., 413461., 
   409280., 399063., 395888., 389819., 383308., 383795., 372386., 
   377394., 366631., 381169., 370698., 370458., 359965., 338567., 
   252587., 243895., 234663., 215924., 188793., 193056., 197482., 
   189589., 179984., 174402., 163136., 157720., 142724., 139104., 
   125494., 114298., 96198., 84893., 71483., 60336., 49822., 39524., 
   31336., 24670., 18835., 13864., 5876., 3507., 1946., 1260., 1130., 
   968., 488., 350., 231., 179.};
f = {358397., 369044., 370305., 374957., 382669., 391063., 389825., 
   392278., 390713., 396610., 388589., 386924., 384382., 386032., 
   393155., 401263., 382722., 381673., 370414., 370901., 364179., 
   350937., 348432., 365904., 372969., 380064., 383041., 388514., 
   388991., 398308., 396483., 398032., 391630., 417629., 423251., 
   426437., 403575., 395808., 397809., 388493., 399157., 420531., 
   444918., 455485., 452475., 443853., 438708., 436616., 433360., 
   443394., 445043., 452670., 447656., 431500., 433817., 431185., 
   431045., 421231., 421791., 419369., 415861., 415005., 406147., 
   413990., 403282., 418967., 412927., 409442., 400765., 381494., 
   287013., 281008., 272477., 251224., 226014., 236255., 247953., 
   243974., 239400., 238560., 233509., 233675., 220211., 221785., 
   207813., 199911., 177746., 162828., 147133., 132731., 118113., 
   99694., 84923., 71615., 57824., 45756., 20755., 13293., 9197., 
   6124., 4666., 5124., 3040., 1790., 1239., 1464.};
lab = {0., 1., 2., 3., 4., 5., 6., 7., 8., 9., 10., 11., 12., 13., 
   14., 15., 16., 17., 18., 19., 20., 21., 22., 23., 24., 25., 26., 
   27., 28., 29., 30., 31., 32., 33., 34., 35., 36., 37., 38., 39., 
   40., 41., 42., 43., 44., 45., 46., 47., 48., 49., 50., 51., 52., 
   53., 54., 55., 56., 57., 58., 59., 60., 61., 62., 63., 64., 65., 
   66., 67., 68., 69., 70., 71., 72., 73., 74., 75., 76., 77., 78., 
   79., 80., 81., 82., 83., 84., 85., 86., 87., 88., 89., 90., 91., 
   92., 93., 94., 95., 96., 97., 98., 99., 100., 101., 102., 103., 
   104., 105};
|improve this answer|||||
$\endgroup$
  • $\begingroup$ In all cases both solutions are very nice Thanks $\endgroup$ – cyrille.piatecki Aug 30 '16 at 8:22
  • $\begingroup$ After looking back at the first code I haven't found explicitely the syntax StringTemplate["-"][5 (# - 1), 5 (# - 1) + 4] & I need a little more help. $\endgroup$ – cyrille.piatecki Aug 30 '16 at 12:07
  • $\begingroup$ @cyrille.piatecki I think C.E. would be the person to ask. I am going to bed in my Timezone, so sorry if I do not respond:) $\endgroup$ – ubpdqn Aug 30 '16 at 12:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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