Public
Edited
May 8, 2023
Insert cell
Insert cell
Insert cell
data = FileAttachment("credit_card_approvals_dataset.csv").csv()
Insert cell
{
for (let i = 0; i < data.length; i++) {
if (data[i]["Approved"] == "1" && data[i]["Ethnicity"] == "White") {
data[i]["Approved_Ethnicity"] = "white_approved"
}
else if (data[i]["Approved"] == "0" && data[i]["Ethnicity"] == "White") {
data[i]["Approved_Ethnicity"] = "white_rejected"
}
else if (data[i]["Approved"] == "1" && data[i]["Ethnicity"] == "Black") {
data[i]["Approved_Ethnicity"] = "black_approved"
}
else if (data[i]["Approved"] == "0" && data[i]["Ethnicity"] == "Black") {
data[i]["Approved_Ethnicity"] = "black_rejected"
}
else if (data[i]["Approved"] == "1" && data[i]["Ethnicity"] == "Asian") {
data[i]["Approved_Ethnicity"] = "asian_approved"
}
else if (data[i]["Approved"] == "0" && data[i]["Ethnicity"] == "Asian") {
data[i]["Approved_Ethnicity"] = "asian_rejected"
}
else if (data[i]["Approved"] == "1" && data[i]["Ethnicity"] == "Latino") {
data[i]["Approved_Ethnicity"] = "latino_approved"
}
else if (data[i]["Approved"] == "0" && data[i]["Ethnicity"] == "Latino") {
data[i]["Approved_Ethnicity"] = "latino_rejected"
}
else if (data[i]["Approved"] == "1" && data[i]["Ethnicity"] == "Other") {
data[i]["Approved_Ethnicity"] = "other_approved"
}
else if (data[i]["Approved"] == "0" && data[i]["Ethnicity"] == "Other") {
data[i]["Approved_Ethnicity"] = "other_rejected"
}

if (data[i]["Gender"] == "0") {
data[i]["Gender"] = "Female"
} else {
data[i]["Gender"] = "Male"
}
if (data[i]["Married"] == "0") {
data[i]["Married"] = "NotMarried"
} else {
data[i]["Married"] = "Married"
}

if (data[i]["Gender"] == "Female" && data[i]["Married"] == "NotMarried") {
data[i]["Gender_Married"] = "Female_NotMarried";
}
else if (data[i]["Gender"] == "Female" && data[i]["Married"] == "Married") {
data[i]["Gender_Married"] = "Female_Married";
}
else if (data[i]["Gender"] == "Male" && data[i]["Married"] == "NotMarried") {
data[i]["Gender_Married"] = "Male_NotMarried";
}
else if (data[i]["Gender"] == "Male" && data[i]["Married"] == "Married") {
data[i]["Gender_Married"] = "Male_Married";
}
}
}
Insert cell
fociFeatures = ({
"white_approved":{x: 200, y: 200},"white_rejected":{x: 410, y: 200},"black_approved":{x: 610, y: 200},"black_rejected":{x: 810, y: 200},
"asian_approved":{x: 200, y: 410},"asian_rejected":{x: 410, y: 410},"latino_approved":{x: 610, y: 410},"latino_rejected":{x: 810, y: 410},
"other_approved":{x: 200, y: 600},"other_rejected":{x: 410, y: 600}
})
Insert cell
clElem = d3.select(svgContainer).select("#layer1")
Insert cell
options = ({
"startFoci": fociFeatures,
"fociField": "Approved_Ethnicity",
"classField": "Gender_Married", // to set their class/color
"dotScaleFactor": 2,
"strength": -1,
"alphaTarget": 0.09,
"collisionFactor": 1.3
})
Insert cell
clusters = dvCluster(clElem,data,800,800,"Age",options)
Insert cell
labelLayer = clElem.append("g").attr("id","labels")
Insert cell
dvClusterFociLabels(labelLayer,fociFeatures,{offsetY:135})
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more