dani
dani

Reputation: 5000

D3: Data join for population pyramid

I have data for years (5-year intervals) and age groups (5-year intervals):

Year  Age   Value   
1970  0_5   5
1970  5_10  4
1970  10_15 2
[...] 
1975  0_5   4
1975  5_10  3 
1975  10_15 2
[...] 

When stepping back and forward in time I would like to compute a data join for this data so that I get a vertical movement. For example the rectangle representing age group 5_10 in 1970 should 5 years later (one step) have transitioned to become the 10_15 rectangle in 1975.

What would be a fairly generic way of solving this?

Upvotes: 0

Views: 257

Answers (1)

There is a very nice sample which does (I think) exactly what you are looking for.

Two of the basic ideas are:

  • Represent the age intervals only by there starting year, such that you can use them for arithmetic
  • Calculate a "Birthyear" for every interval, such that transitions will occur between intervals of the same birthyear. (birthyear = year - age)

I.e. you would represent/convert your data like this:

Year  Age  Birthyear  Value   
1970  0    1970       5
1970  5    1965       4      <-- 5_10 in 1970
1970  10   1960       2
[...] 
1975  0    1975       4 
1975  5    1970       3
1975  10   1965       2      <-- 10_15 in 1975
[...] 

Upvotes: 2

Related Questions