Public
Edited
Oct 26, 2022
Insert cell
Insert cell
Insert cell
bdDeathsAge = FileAttachment("bd-deaths-age.csv").csv()
Insert cell
Insert cell
bd = bdDeathsAge.filter((d)=>(d.Sex!="Total" && d.Age!= "Total" && d.Age!= "Infant")).map(
function (d) {
return {data_b: Number(d.Period),
pol: (d.Sex).substring(0,1).toUpperCase(),
age: fun_get_age(d.Age),
count_b: Number(d.Count)}
}).sort((a, b) => a["data_b"] > b["data_b"] ? 1 : -1)
Insert cell
Insert cell
function fun_get_age(object) {
var r = /\d+/;
return Number((String(object)).match(r)[0]);
}
Insert cell
Insert cell
viewof table_bd = Inputs.table(bd, {maxHeight: 150})
Insert cell
Insert cell
bd_2021 = bd.filter(d=>d["data_b"]==2021)
Insert cell
Plot.plot({
width : 900,
height : 300,
grid : true,
facet: {
data: bd_2021,
x: "age",
margin: 30
},
marks: [
Plot.barY(bd_2021, {x: "pol", y: "count_b", fill:"pol"}),
Plot.ruleY([0, 2000,3000]),
//Plot.text(bd, {x: "data_b", y: "count_b", fill: "age" , dy: , text: d=>d["count_b"]}),
], color: { range: colors, legend: true},
margintop: 30})
Insert cell
Insert cell
viewof select_date = Inputs.select(new Set(bd.map(d => d["data_b"])), {label: "Год исследования"})
Insert cell
Plot.plot({
width :1000,
height : 400,
grid : true,
y: {
domain: [1, 4000]
},
marks: [
Plot.barY(bd.filter(x=> x.data_b==select_date && x.pol=='M'), {x: "age", y: "count_b", fill: "grey" , fillOpacity: 0.4}),
Plot.barY(bd.filter(x=> x.data_b==select_date && x.pol=='F'), {x: "age", y: "count_b", fill: "red", fillOpacity: 0.4}),
Plot.ruleY([0]),
Plot.text(bd.filter(x=> x.data_b==select_date && x.pol=='M'), {x: "age", y: "count_b", fill: "black", dy: -10, text: d=>d["count_b"]}),
Plot.text(bd.filter(x=> x.data_b==select_date && x.pol=='F'), {x: "age", y: "count_b", fill: "red" , dy:-80, text: d=>d["count_b"]}),
],color: { legend: true, range:["orange", "brown"]},
marginLeft: 100})
Insert cell
Insert cell
Plot.plot({
width :700,
height : 400,
grid : true,
facet: {
data: bd,
y: "pol",
margin: 50
},
y: {
domain: [1, 3000]
},
marks: [
Plot.ruleY([0, 1000, 2000, 3000]),
Plot.barY(bd, Plot.groupX({y: "mean"}, {x: "age", y: "count_b",fill: "pol" })),
],
color: { range: colors, legend: true}
})
Insert cell
colors = ["#7fa074","#90719f","#2c4b27","#2d223c","#dec5da","#c1d1aa","#574571","#0e2810","#b695bc","#466c4b","#ffa074","#9a719f","#2f4b27","#22223c", "orange", "brown","#af9980"]
Insert cell
Insert cell
Для нашего датасета определим: есть (наблюдается) тенденция (рост, снижение) суммарного количества людей всех возрастов из года в год (отдельно для каждой гендерной группы)?
Insert cell
Plot.plot({
width :900,
height : 300,
facet: {
data: bd,
x: "pol",
margin: 50
},
y: {
domain: [0, 17000]
},
marks: [
Plot.ruleY([0, 15000, 17000]),
Plot.barY(bd, Plot.groupX({y: "sum"}, {x: "data_b", y: "count_b",fill: "data_b" })),
],
color: { legend: true , scheme: "magma"},
grid : true
})
Insert cell
Insert cell
Plot.plot({
width :900,
height : 400,
facet: {
data: bd,
x: "data_b",
margin: 40
},
y: {
domain: [0, 18000]
},
marks: [
Plot.ruleY([0, 15000, 17000]),
Plot.barY(bd, Plot.groupX({y: "sum"}, {x: "pol", y: "count_b",fill: "pol" })),
],
color: { legend: true },
grid : true
})
Insert cell
Insert cell
Plot.plot({
width: 1000,
grid: true,
y: {
percent: true,
domain: [0, 18]
},
marks: [
Plot.barY(bd_2021, Plot.groupX({y: "proportion"}, {y: "count_b", fill:"pol", x:"age"})),
Plot.text(bd_2021, Plot.groupX({y: "proportion", text:"first"}, {y: "count_b", x:"age", dy: -5, dx: -15, text:"count_b"})),
Plot.text(bd_2021, Plot.groupX({y: "proportion", text:"last"}, {y: "count_b", x:"age",dy: -5, dx: 10, text:"count_b"})),
Plot.ruleY([0])
]
})
Insert cell
Insert cell
Insert cell
Insert cell
diskD = FileAttachment("disk_d@7.csv").csv({typed:true})
Insert cell
Insert cell
diskD[1].dir_file.split("\\")
Insert cell
diskD[1].dir_file.split("\\").pop()
Insert cell
Insert cell
Sunburst(diskD, {
path: (d) => d.dir_file.replaceAll("\\", "\/"),
label: (d) => d.dir_file.split("\\").pop()+(d.size!=null?"("+String(d.size)+")":""),
value: (d) => d?.size,
// title: (d, n) => [n.id, n.value.toLocaleString()].join("\n"),
width,
height: 700
})
Insert cell
Insert cell
subj = FileAttachment("disk_d2@5.csv").csv({typed:true})
Insert cell
Insert cell
Pack(subj, {
path: (d) => d.subject.replaceAll(":", "\/"),
label: (d) => d.subject.split(":").pop()+(d.count_stud!=null?"\n("+String(d.count_stud)+")":"..."),
value: (d) => d?.count_stud,
//title: (d, n) => [n.id, n.value.toLocaleString()].join("\n"),
width,
height: 700
})
Insert cell
import {Pack} from "@d3/pack"
Insert cell
import {Sunburst} from "@d3/sunburst"
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