Public
Edited
Nov 20, 2022
1 fork
Insert cell
Insert cell
Insert cell
Insert cell
Wrangler(data)
Insert cell
data_procesada = aq
.from(data)
.select("season", "fb", "sl", "ct", "cb", "ch", "sf", "kn", "xx")
.fold(["fb", "sl", "ct", "cb", "ch", "sf", "kn", "xx"])
.orderby("season")
.objects()
Insert cell
data_final = data_procesada.map((d) => ({
season: new Date(d.season + "-01-01"),
key: d.key,
value: +d.value * 100
}))
Insert cell
data = d3.csv("https://download.data.world/s/ijpomkwfgk64gz6sb2umqsvdoilbki")
Insert cell
import { IndexChart } from "@d3/index-chart"
Insert cell
chart1 = Plot.line(
data_final,
Plot.normalizeY({ x: "season", y: "value", stroke: "key" })
).plot({ color: { legend: true }, y: { type: "linear", grid: false } })
Insert cell
chart2 = Plot.line(data_final, {
x: "season",
y: "value",
stroke: "key"
}).plot({
color: { legend: true }
})
Insert cell
data_final
Insert cell
chart = IndexChart(data3_final, {
x: (d) => d.season,
y: (d) => d.value,
z: (d) => d.key,
yType: d3.scaleLinear,
yLabel: "↑ % lanzamiento (×)",
width,
height: 400
})
Insert cell
w43Queryresult2 = FileAttachment("2022w43-QueryResult (2).csv").csv()
Insert cell
d3.extent(data_final.map((d) => d.value))
Insert cell
data_final
Insert cell
data3 = d3.csv("https://download.data.world/s/kunkw3hdrkrivf5rphvb4kftglvrw6")
Insert cell
Wrangler(mom_w44)
Insert cell
data3_final = aq
.from(data3)
.fold(["ip", "pitches"])
.objects()
.map((d) => ({
season: new Date(d.season + "-01-01"),
key: d.key,
value: +d.value * 100
}))
Insert cell
Insert cell
Insert cell
Insert cell
d3.schemeTableau10
Insert cell
// d3.scaleOrdinal([[domain, ]range])
//
// Constructs a new ordinal scale with the specified domain and range. If domain is not specified, it defaults to the empty array. If range is not specified, it defaults to the empty array; an ordinal scale always returns undefined until a non-empty range is defined.

d3.scaleOrdinal(["A", "B", "C"], ["red", "green", "blue"])
Insert cell
mom_w44 = d3.csv(
"https://download.data.world/s/mvwshoefvhfiau7blcw5matldtmrvx",
d3.autoType
)
Insert cell
// To use copied code replace "data" with your own variable
mom_w44_stats = aq
.from(mom_w44)
.select("party", "chamber", "raised")
.groupby("party", "chamber")
.rollup({
mean: (d) => op.mean(d["raised"]),
sum: (d) => op.sum(d["raised"]),
count: (d) => op.count()
})
.objects() // Uncomment to return an array of objects
Insert cell
Plot.plot({
facet: {
data: mom_w44_stats,
y: "chamber"
},
marks: [
Plot.barX(mom_w44_stats, {
x: "sum",
y: "party",
fill: "party",
sort: { y: "x", reverse: true }
}),
Plot.ruleX([0])
],
color: {
type: "categorical",
range: ["#4e79a7", "#f28e2c", "#e15759"],
legend: true,
columns: "80px"
},
marginLeft: 120
// marginRight: 200
// height: 200
// width: width
})
Insert cell
membersByPartyChamber = d3.group(
mom_w44,
(d) => d.party,
(d) => d.chamber
)
Insert cell
d3.rollup(
mom_w44,
(v) => d3.sum(v, (d) => d.raised),
(d) => d.party
)
Insert cell
Insert cell
Insert cell
// En este dataset sólo estan los datos de USA
tmp = d3.csv(
"https://download.data.world/s/ibjfmujmitmsc64h3zpqxmphe5un36",
d3.autoType
)
Insert cell
// lo vuelvo a leer, saco las primeras 2 columnas y alias al resto.
w45_wide = d3.csv(
"https://download.data.world/s/h5wv7bf7mupvfux3bhxxbadha443ej",
d3.autoType
)
Insert cell
w45 = aq
.from(w45_wide)
.fold(["alone", "children", "coworkers", "friends", "partner", "family"])
.rename({ year: "age" })
.objects()
Insert cell
w45_agrupado = [
...d3.rollup(
w45,
(v) => d3.sum(v, (d) => d.value),
(d) => d.key
)
].map((d) => ({ key: d[0], value: d[1] }))
Insert cell
Plot.plot({
marks: [
Plot.barX(w45_agrupado, {
x: "value",
y: "key",
sort: { y: "x", reverse: true },
fill: "darkolivegreen"
}),
Plot.ruleX([0])
],
marginLeft: 80
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { LineChart } from "@d3/multi-line-chart"
Insert cell
// la funcion LineChart espera que X sea una fecha
//
mLineChart = LineChart(w45, {
x: (d) => d.age,
y: (d) => d.value,
z: (d) => d.key,
yLabel: "↑ time (%)",
width,
height: 500,
color: "steelblue",
voronoi // if true, show Voronoi overlay
})
Insert cell
voronoi = false
Insert cell
Insert cell
w46 = d3.csv(
"https://download.data.world/s/ta2wqz4b56s66rckiezmffqfq4mool",
d3.autoType
)
Insert cell
d3.extent(w46, (d) => d.year)
Insert cell
w46_4c = aq
.from(w46)
.select("drug", "year", "wholesale_price", "retail_price")
.relocate("drug", { after: "year" })
.fold(["wholesale_price", "retail_price"])
.objects()
.map((d) => ({
year: new Date(d.year, 1, 1),
drug: d.drug,
key: d.key,
value: d.value
}))
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