Published
Edited
Aug 14, 2021
2 stars
Insert cell
Insert cell
Insert cell
vega({
$schema: "https://vega.github.io/schema/vega-lite/v5.json",
title:
"Proportion of Homeowners who are Immigrants, Canadian Geographies - Top 20",
data: {
values: PropImmigrantOwners.slice(0, 20)
.concat(popLookup)
.map(d => {
return {
DESC: '% Properties Immigrant Owned (2019 Survey)',
...d
};
})
},
mark: "bar",
width: 500,
encoding: {
y: {
field: "GEO",
sort: "-x"
},
row: {
field: "DESC"
},
x: {
field: "VALUE",
type: "quantitative"
},
color: {
field: "DESC"
}
}
})
Insert cell
MedianAge = data
.filter(
d =>
d.Estimates === 'Median age of property owners' &&
d['Other immigration characteristics'] === 'Total, all places of birth' &&
d['Number of residential properties owned'] ===
'Total, all number of properties owned categories' &&
d['Immigration status'] === "Total, all immigration status"
)
.reduce((accum, d) => {
accum[d.GEO] = {
geo: d.GEO,
medianAssessValue: d.VALUE
};
return accum;
}, {})
Insert cell
PropOwnedWithMedianAssess = {
let both = [];
for (let i in MedianAssessValues) {
both.push({
geo: i,
AssessmentValue: MedianAssessValues[i].medianAssessValue,
PropOwned: PropOwned[i].medianAssessValue,
MedianAge: MedianAge[i].medianAssessValue
});
}

return both;
}
Insert cell
PropOwned = data
.filter(
d =>
d.Estimates === 'Immigration status, percentage' &&
d['Other immigration characteristics'] === 'Total, all places of birth' &&
d['Number of residential properties owned'] ===
'Total, all number of properties owned categories' &&
d['Immigration status'] === "Immigrant"
)
.reduce((accum, d) => {
accum[d.GEO] = {
geo: d.GEO,
medianAssessValue: d.VALUE
};
return accum;
}, {})
Insert cell
MedianAssessValues = data
.filter(
d =>
d.Estimates === 'Median of total assessment value' &&
d['Other immigration characteristics'] === 'Total, all places of birth' &&
d['Number of residential properties owned'] ===
'Total, all number of properties owned categories' &&
d['Immigration status'] === "Total, all immigration status"
)
.reduce((accum, d) => {
accum[d.GEO] = {
geo: d.GEO,
medianAssessValue: d.VALUE
};
return accum;
}, {})
Insert cell
PropImmigrantOwners = data
.filter(
d =>
d.Estimates === 'Immigration status, percentage' &&
d['Other immigration characteristics'] === 'Total, all places of birth' &&
d['Number of residential properties owned'] ===
'Total, all number of properties owned categories' &&
d['Immigration status'] === "Immigrant"
)
.sort((a, b) => b.VALUE - a.VALUE)
Insert cell
stats = data.reduce((accum, d) => {
accum[d.Estimates] = 1;
return accum;
}, {})
Insert cell
data = FileAttachment("46100052.csv").csv({ typed: true })
Insert cell
popLookup = {
let popImmigrantLookup = {};
for (let d of popImmigrantData) {
popImmigrantLookup[d.GEO_NAME] =
d[
'Dim: Mother tongue (4): Member ID: [1]: Total - Mother tongue (Note: 155)'
];
}

let popNonImmigrantLookup = {};
for (let d of popNonImmigrantData) {
popNonImmigrantLookup[d.GEO_NAME] =
d[
'Dim: Mother tongue (4): Member ID: [1]: Total - Mother tongue (Note: 155)'
];
}

let combined = [];
for (let i in popImmigrantLookup) {
combined.push({
geo: i,
value:
(popImmigrantLookup[i] /
(popImmigrantLookup[i] + popNonImmigrantLookup[i])) *
100
});
}

let geomap = {
Toronto: 'Toronto, Census metropolitan area (CMA)',
Vancouver: 'Vancouver, Census metropolitan area (CMA)',
Ontario: 'Ontario',
'British Columbia': 'British Columbia',
'Abbotsford - Mission':
'Abbotsford - Mission, Census metropolitan area (CMA)',
'Kitchener - Cambridge - Waterloo':
'Kitchener - Cambridge - Waterloo, Census metropolitan area (CMA)',
Hamilton: 'Hamilton, Census metropolitan area (CMA)',
Oshawa: 'Oshawa, Census metropolitan area (CMA)',
Guelph: 'Guelph, Census metropolitan area (CMA)',
'Ottawa - Gatineau (Ontario part)':
'Ottawa - Gatineau (Ontario part), Census metropolitan area (CMA) – provincial part',
Windsor: 'Windsor, Census metropolitan area (CMA)',
Squamish: 'Squamish, Census agglomeration (CA)',
London: 'London, Census metropolitan area (CMA)',
Victoria: 'Victoria, Census metropolitan area (CMA)',
Barrie: 'Barrie, Census metropolitan area (CMA)',
'Wasaga Beach': 'Wasaga Beach, Census agglomeration (CA)',
'St. Catharines - Niagara':
'St. Catharines - Niagara, Census metropolitan area (CMA)',
Parksville: 'Parksville, Census agglomeration (CA)',
Nanaimo: 'Nanaimo, Census agglomeration (CA)',
Leamington: 'Leamington, Census agglomeration (CA)'
};

let combinedMap = {};
for (let d of combined) {
combinedMap[geomap[d.geo]] = d.value;
}

delete combinedMap[undefined];

let combinedArray = [];
for (let d in combinedMap) {
combinedArray.push({
GEO: d,
VALUE: combinedMap[d],
DESC: "% Total Population Immigrants (2016 Census)"
});
}

return combinedArray;
}
Insert cell
popImmigrantData = (await FileAttachment("popImmigrants.csv").csv({
typed: true
})).filter(
d =>
d['DIM: Immigrant status and period of immigration (10)'] ===
'Total - Immigrant status and period of immigration'
)
Insert cell
popNonImmigrantData = (await FileAttachment("popNonImmigrants.csv").csv({
typed: true
})).filter(
d =>
d['DIM: Immigrant status and period of immigration (10)'] ===
'Total - Immigrant status and period of immigration'
)
Insert cell
vega = require("vega-embed@6")
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more