Hello!
I’m exploring the change of address (COA) dataset from the US Postal Service, and I’d like to create small multiples for each state and show aggregates of a couple values.
The data looks something like this:
[{
YYYYMM: 202001
ZIPCODE: "00601"
CITY: "ADJUNTAS"
STATE: "PR"
TOTAL FROM ZIP: 13
TOTAL BUSINESS: 0
TOTAL FAMILY: 0
TOTAL INDIVIDUAL: 0
TOTAL PERM: 0
TOTAL TEMP: 0
TOTAL TO ZIP: 0
}, {
YYYYMM: 202001
ZIPCODE: "00602"
CITY: "AGUADA"
STATE: "PR"
TOTAL FROM ZIP: 25
TOTAL BUSINESS: 0
TOTAL FAMILY: 0
TOTAL INDIVIDUAL: 27
TOTAL PERM: 34
TOTAL TEMP: 0
TOTAL TO ZIP: 40
}, {
...
}]
Where each object represents a zip code. You can get a copy of the data yourself here.
I’m trying to facet by STATE
, and in each facet, I’d like to show a bar for the sum of TOTAL FROM ZIP
and TOTAL TO ZIP
, and perhaps even a drive NET
value that equals the difference between the aggregate TO
and FROM
values.
I’ve tried using the facet
option with a groupX
mark, but the values I’m interested in are not discrete, so I wonder if that’s the problem.
Is there a way to use the Plot
API to transform the data into whatever format facet is looking for?
Should I just do the aggregation first and feed the calculated values to Plot
, so they look like this on the way in?
[{
"STATE": "PR",
"TOTAL TO ZIP": 10000,
"TOTAL FROM ZIP": 5000
}, {
"STATE": "CA",
"TOTAL TO ZIP": 5000000,
"TOTAL FROM ZIP": 40000,
}, {
...
}]
Thanks!