Published
Edited
Jul 26, 2021
Fork of Auto Loan
Insert cell
md `# Auto Loan Plot Analysis`
Insert cell
myLoan = FileAttachment("autoloan.csv").csv({typed: true})
Insert cell
myLoan2 = myLoan.map( d => (
{
Vehicle_Make: d.Vehicle_Make,
Vehicle_Model: d.Vehicle_Model,
Loan_Amount: d.Loan_Amount,
Branch_code: d.Branch_code,
Annual_Income: d.Annual_Income,
Interest_Rate: d.Interest_Rate*100,
Income_Level: parseIncome( d.Annual_Income ),
}
)
)
.sort((a, b) => b.Loan_Amount - a.Loan_Amount)
Insert cell
md` ## Added Income_Level as a value`
Insert cell
md` ### Created a function to convert string to value`
Insert cell
parseIncome = function income(d) {
let n
switch ( d[0] ) {
case '2': n = 12000; break;
case '3': n = 18000; break;
case '4': n = 24000; break;
case '5': n = 48000; break;
case '6': n = 72000; break;
case '7': n = 96000; break;
case '8': n = 120000; break;
case '9': n = 150000; break;
defaut: n = 0;
}
return n
}
Insert cell
incomeRange = [ 12000,18000, 24000, 48000, 72000, 96000, 120000, 150000 ]
Insert cell
Inputs.table(myLoan2)
Insert cell
md`### Get all car brands`
Insert cell
carBrandList = _.uniqBy(myLoan, d => d.Vehicle_Make)
.map(d => d.Vehicle_Make)
.sort()

Insert cell
md`## Use pulldown menu to select car brand to filter`
Insert cell
viewof carBrand = Inputs.select([null].concat(carBrandList), {label: "Make"})
Insert cell
md`## Drag slider for number of results to return`
Insert cell
viewof results = Inputs.range([50, 500], {value: 50, step: 10, label: "Results"})
Insert cell
carBrandLoan = myLoan2.map( d => (
{
Vehicle_Model: d.Vehicle_Model,
Vehicle_Make: d.Vehicle_Make,
Loan_Amount: d.Loan_Amount,
Branch_code: d.Branch_code,
Annual_Income: d.Annual_Income,
Income_Level: parseIncome( d.Annual_Income ),
}
)
)
.filter(d => d.Vehicle_Make == carBrand )
.sort((a, b) => b.Loan_Amount - a.Loan_Amount)
.splice(0,results)

Insert cell
Plot.plot({
width:1200,
height: 600,
grid: true,
inset: 10,
marginLeft: 150,
x: {
label: "Amount (000)",
transform: f => f / 1000,
padding: 0.8
},
y: {
label: "Model",
padding: 2,
},
marks: [
//Plot.ruleY([0]),
//Plot.dot(carBrandLoan, Plot.binX( {color: "count"}, {y: "Vehicle_Model", x: "Loan_Amount", fill:"Branch_code"})),
Plot.dot(carBrandLoan, Plot.binX( {fill: "count"}, {y: "Vehicle_Model", x: "Loan_Amount", fill:"Branch_code"})),
]
})
Insert cell
Inputs.table(carBrandLoan)
Insert cell
md` ## All Brands vs Loan Amount`
Insert cell
Plot.dot(myLoan2, {y: "Vehicle_Make", x: "Loan_Amount", stroke:"Loan_Amount"}).plot({
width:1200,
height: 600,
grid: true,
inset: 10,
marginLeft: 120,
y: {
label: "Make",
padding: 0.1
},
x: {
label: "Amount (000)",
padding: 0.1,
transform: f => f / 1000,
},
})

Insert cell
Plot.plot({
width:1200,
height: 800,
grid: true,
inset: 10,
marginLeft: 150,
x: {
label: "Amount (000)",
transform: f => f / 1000,
padding: 0.8
},
y: {
label: "Make",
padding: 0.2
},
marks: [
//Plot.ruleY([0]),
Plot.barX(myLoan2, {y: "Vehicle_Make", x: "Loan_Amount", stroke:"Loan_Amount"}),
]
})
Insert cell
md `### Income level vs Vehicle Make`

Insert cell
Plot.plot({
width:1200,
height: 800,
grid: true,
inset: 10,
marginLeft: 150,
x: {
label: "Amount (000)",
padding: 0.8
},
y: {
label: "Make",
padding: 0.2
},
marks: [
//Plot.ruleY([0]),
Plot.dot(myLoan2, {y: "Vehicle_Make", x: "Income_Level", stroke:"Income_Level"}),
]
})
Insert cell
md`### Corelation between loan amount and branch`
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