Public
Edited
Nov 16, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
d3 = require("d3@6")
Insert cell
Insert cell
carList=d3.csv("https://raw.githubusercontent.com/2EZ4RTZzz/IAT355/main/cars_original.csv",d3.autoType)

Insert cell
Insert cell
CarsInfoMap = carList.map(d =>{
var a =d;
a.Retail_Price = +d.Retail_Price;
a.Dealer_Cost = +d.Dealer_Cost;
a.Engine_Size = +d.Engine_Size;
a.Cyl = +d.Cyl;
a.HP = +d.HP;
a.City_MPG = +d.CityMPG;
a.Hwy_MPG = +d.Hwy_MPG;
a.Weight = +d.Weight;
a.Wheel_Base = +d.Wheel_Base;
a.Len = +d.Len;
a.Width = +d.Width;

return a;
})
Insert cell
Insert cell
Insert cell
MaxRetailPrice = d3.max(carList, d => d["Retail_Price"])
//Porsche 911 GT2 2dr
Insert cell
MinRetailPrice = d3.min(carList, d => d["Retail_Price"])
//Kia Rio 4dr manual
Insert cell
MaxEngineCyl = d3.max(carList,d => d["Engine_Size"])
//Dodge Viper SRT-10 convertible 2dr
Insert cell
MinEngineCyl = d3.min(carList,d => d["Engine_Size"])
//MAZDA rx
Insert cell
MaxWeight = d3.max(carList, d => d["Weight"])
//Ford Excursion 6.8 XLT
Insert cell
MinWeight = d3.min(carList, d => d["Weight"])
//Kia Amanti 4dr???
//google the correct data: 3,770 kg (8,311 lb)
Insert cell
Insert cell
MaxHP = d3.max(carList,d => d["HP"])
//Dodge Viper SRT-10 convertible 2dr
Insert cell
MinHP = d3.min(carList, d => d["HP"])
//Honda Insight 2dr (gas/electric)
Insert cell
Insert cell
Insert cell
SumHP = d3.sum(carList,d=>d["HP"])
//so the total car horsepower sum together is 92399
Insert cell
SumEngineSize = d3.sum(carList,d => d["Engine_Size"]).toFixed(2);
//total around 1368.2
Insert cell
SumRetailPrice = d3.sum(carList,d=>d["Retail_Price"])
//the sum retail price is 14027638
Insert cell
AvgDealerCost = d3.mean(carList, d => d["Dealer_Cost"]).toFixed(2);
//so the avg car dealer price is around 30k
Insert cell
AvgCityMPG = d3.mean(carList,d => d["Cyl"]).toFixed(2);
//the Average cyl is around 5.78
Insert cell
AvgWeight = d3.mean(carList,d => d["Weight"]).toFixed(2);
//around 3560.5
Insert cell
Insert cell
CountOverHP = carList.filter(d => (d.HP>300)).length
//counting how many car's HorsePower over 300+
Insert cell
CountOverAvgPrice = carList.filter(d => (d.Dealer_Cost>AvgDealerCost)).length
//check how many car's dealer cost over the average of dealer cost
Insert cell
CountWeight = carList.filter(d => (d.Weight>AvgWeight)).length
//check how many car's weight higher than avg car weight
Insert cell
Insert cell
Insert cell
Insert cell
import {vl} from '@vega/vega-lite-api'
Insert cell
Insert cell
FourWheelCarList ={
let i = 0;
let totalSports = [];
for(i = 0 ; i<carList.length; i++){
if(carList[i]["AWD"] == "Yes"){
totalSports.push(carList[i]);
}
}
return totalSports;
}
Insert cell
vl.markBar()
.data(FourWheelCarList)
.encode(
vl.x().fieldQ('Retail_Price').bin({step:(10000)}),
vl.y().count(),
vl.color().fieldN("SUV"),
)
.render()
Insert cell
Insert cell
vl.markBar()
.data(FourWheelCarList)
.encode(
vl.x().fieldQ('Dealer_Cost').bin({step:(10000)}),
vl.y().count(),
vl.color().fieldN("SUV"),
)
.render()

Insert cell
Insert cell
vl.markBar()
.data(FourWheelCarList)
.encode(
vl.x().fieldQ('Engine_Size').bin({step:(0.5)}),
vl.y().count(),
vl.color().fieldN("SUV"),
)
.render()
Insert cell
Insert cell
vl.markBar()
.data(FourWheelCarList)
.encode(
vl.x().fieldQ('HP').bin({step:(50)}),
vl.y().count(),
vl.color().fieldN("SUV"),
)
.render()
Insert cell
Insert cell
vl.markBar()
.data(FourWheelCarList)
.encode(
vl.x().fieldQ('Weight').bin({step:(1000)}),
vl.y().count(),
vl.color().fieldN("SUV"),
)
.render()

Insert cell
Insert cell
Insert cell
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