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

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more