Published
Edited
Jun 9, 2021
Importers
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
data = {
return sondages.slice(0, sondagesNb)
.map(s => s.tours[0].hypotheses.map(h => h.candidats.map(c =>({sondage: s.id, hypothese: h.hypothese, ...c}))))
.flat(10)
}
Insert cell
moyennes = [...d3.rollup(data, v => ({
echantillons: v.length,
moyenne: d3.mean(v.map(c=>c.intentions)),
inf:d3.mean(v.map(c=>c.erreur_inf)),
sup:d3.mean(v.map(c=>c.erreur_sup))
}),
c => c.candidat)
]
.map(x => ({candidat: x[0], ...x[1]}))
.filter(c => candidatsSelected.includes(c.candidat))
.sort((a,b)=> b.moyenne - a.moyenne)
Insert cell
Insert cell
Insert cell
t2 = {
return sondages.slice(0, sondagesNb)
.map(s => s.tours[1].hypotheses.map(h => h.candidats.map(c =>({sondage: s.id, hypothese: h.hypothese?.replace(' / ', '-'), ...c}))))
.flat(10)
}
Insert cell
moyennes2 = [...d3.rollup(t2, v => ({
echantillons: v.length,
moyenne: d3.mean(v.map(c=>c.intentions)),
inf:d3.mean(v.map(c=>c.erreur_inf)),
sup:d3.mean(v.map(c=>c.erreur_sup))
}), c => c.candidat)].map(x => ({candidat: x[0], ...x[1]}))
.filter(c => candidatsSelected.includes(c.candidat))
.sort((a,b)=> b.moyenne - a.moyenne)
Insert cell
Insert cell
intentionsChart = (candidat) => {
let current = data.filter(s => s.candidat == candidat)
let h = current.length * 30
let plot = Plot.plot({
height: h,
marginRight: 250,
x: {
domain: [0, 50],
grid: true,
label: "intentions de vote",
labelAnchor: 'center'
},
y: {
type: 'band',
axis: 'right',
padding: 0.25,
domain: current.map(s => `${s.sondage} : ${s.hypothese}`)
},
marks:[
Plot.ruleX([moyennes.find(c=> c.candidat == candidat).inf, moyennes.find(c=> c.candidat == candidat).sup], {stroke: 'red', strokeOpacity: 0.2 }),
// Plot.bar(current, { x1: 'erreur_inf', x2: 'erreur_sup', y: s => `${s.sondage} : ${s.hypothese}`, fill: '#ccc'}),
Plot.barX(current, { x1: 'erreur_inf', x2: 'erreur_sup', y: s => `${s.sondage} : ${s.hypothese}`, fill: '#ccc'}),
Plot.tickX(current, { x: 'intentions', y: s => `${s.sondage} : ${s.hypothese}` }),
Plot.ruleX([moyennes.find(c=> c.candidat == candidat).moyenne], {stroke: 'red', strokeOpacity: 0.5 })
]
})
return plot
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Inputs.table(sondages)
Insert cell
sondages = sondages_.sort((a,b) => b.fin_enquete.localeCompare(a.fin_enquete))
Insert cell
import { candidats, sondages as sondages_ } from '@taniki/presidentielles2022-sondages-suivi'
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