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 would like to create a histogram for human population by age, but the $2010$ census data I have available is for five uneven cohorts: ages $0$-$17$, $18$-$24$, $25$-$44$, $45$-$64$, and $65+$. My county has the following data: {86031, 26671, 91927, 93983, 32232}, for a total population of $330844$. The corresponding histogram bins should have widths {17, 7, 20, 20, 20} and heights {86031/17, 26671/7, 91927/20, 93983/20, 32232/20}. I will eventually want to make this pretty by adding labels, etc., but I don't see how to even get started.

share|improve this question
2  
The second argument of the Histogram function directly specifies the bins to use. Histogram[{x1,x2},bspec] plots a histogram with bin width specification bspec. –  bill s Nov 8 '13 at 4:14
    
add comment

3 Answers

Based solely on the information provided IMO you need to use RectangleChart. I'm not sure how to create the histogram you desire using Histogram and only the information in your question

enter image description here

-- here is the RectangleChart implementation:

{widths, totals} = {{17, 7, 20, 20, 20}, {86031, 26671, 91927, 93983, 
   32232}}; 
RectangleChart[Transpose@{widths, totals/widths}]

enter image description here

You can make this pretty:

RectangleChart[Transpose@{widths, totals/widths},
 BarSpacing -> 2,
 ChartBaseStyle -> EdgeForm[Dashed],
 ChartElementFunction -> "FadingRectangle", 
 ChartLabels -> {"0-17", "18-24", "25-44", "45-64", "65+"}, 
 ChartStyle -> ColorData["Charting"],
 BaseStyle -> Directive[FontFamily -> "Arial", 12],
 PerformanceGoal -> "Speed"]

enter image description here

share|improve this answer
add comment

The natural way is to use RectangleChart since your data is already processed.

I will just show how to use Histogram for your purposes, it requires step back to create the data, that's why Mike's solution is better.

data = {{{0, 17}, {17, 24}, {24, 44}, {44, 64}, {64, 84}}, 
        {86031, 26671, 91927, 93983, 32232}};

dat = RandomReal[#, Round[#2/Abs[Subtract @@ #]]] & @@@ Transpose[data];

Histogram[dat, {{0, 17, 24, 44, 64, 84}}]

enter image description here

share|improve this answer
    
I guess thats what I meant in my answer. The data presented in the question is already binned/aggregated so Histogram is the wrong choice in this instance unless you go backwards first. –  Mike Honeychurch Nov 8 '13 at 7:55
    
The RectangleChart approach Mike Honeychurch proposes is certainly more in keeping with my Mathematica skills. Kuba's solution — apparently by generating random data in the proper bins in the proper amounts to create the desired histogram — is awesome, but beyond my ability! –  R. Peter DeLong Nov 9 '13 at 17:03
add comment

Alternatively you can fix both the bin end points and their heights explicitly. I've set 120 as a reasonable endpoint for the last bin. The zero in the input data is just there as a place holder and is effectively ignored.

Histogram[{0}, {{0, 18, 25, 45, 65, 120}}, {86031/17, 26671/7, 
   91927/20, 93983/20, 32232/20} &]

enter image description here

I would use the rectangle chart approach as others have suggested but this at least gives a way to use the height function to do what you are wanting without resorting to sampling.

Obviously if you want to label the axis differently you can use Ticks.

Histogram[{0}, {{0, 18, 25, 45, 65, 120}}, {86031/17, 26671/7, 
   91927/20, 93983/20, 32232/20} &, 
     Ticks -> {{{(0 + 17)/2, "0-17"}, {(18 + 24)/2, "18-24"}, {(25 + 44)/
        2, "25-44"}, {(45 + 64)/2, "45-64"}, {(65 + 120)/2, "65+"}}, Automatic}]

enter image description here

share|improve this answer
add comment

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.