plot2 = Plot.plot({
y: { grid: false, reverse: true},
x: {tickFormat: Math.abs, axis: null,},
marginLeft: 100,
marginRight: 100,
paddingRight: 100,
marginTop: 50,
marginBottom: 80,
width: 800,
height: 600,
label: null,
tooltip: {
stroke: "white",
},
marks: [
Plot.axisX({ticks: [ -100000, -200000, -300000, -400000, -500000],
tickFormat: d => Math.abs(d)/1000, fontSize:0, dx:-20, dy:5}),
Plot.axisX({ ticks: [ 100000, 200000, 300000, 400000, 500000],
tickFormat: d => Math.abs(d)/1000, fontSize:0, dx: 20, dy:5}),
Plot.axisY({
frameAnchor: "middle",
dx: 39,
tickSize: 30,
ticks: [0,10,20,30,40,50,60,70,80,90,100],
label: null,
stroke: "white",
textStroke: "white",
textStrokeWidth: 0,
fontSize: 14
}),
Plot.text(["↑ Ages"], { frameAnchor: "top", dy: -20, dx: -4, fontSize:15 }),
Plot.barX(df2, { filter: (d) => d.age <= Age, x: (d) => -d.hommes, y: "age", dx: -20,
channels: {Hommes: {value: 'hommes', label: "Nombre d'hommes:"},
Age: {value: 'age', label: 'Age:'},
annee: {value: "annee", label: 'Année de naissance:'}},
fill: "#512672", fillOpacity: 1,
stroke: '#512672', strokeWidth: 3 ,
rx1: 5, rx2: 0, inset:-.1,
tip: {format: {x: false, y: false, annee: "d",},anchor: "top", stroke: "transparent"}}),
Plot.barX(df2, {filter: (d) => d.age <= Age, x: (d) => d.femmes , y: "age", dx: 20,
channels: {Femmes: {value: 'femmes', label: 'Nombre de femmes:'},
Age: {value: 'age', label: 'Age:'},
annee: {value: "annee", label: 'Année de naissance:'}},
fill: "#ff554e", fillOpacity: 1,
stroke: '#ff554e', strokeWidth: 3 ,
rx1: 0, rx2:5, inset: -.1,
tip: {format: {x: false, y: false, annee: "d"}, anchor: "bottom", stroke: "transparent"} }),
Plot.image(ages1,{filter: (d) => d.age <= Age, x: "xc", y: "yc" , src: "img",
channels: {xc: {value: 'xx', label: ''},
yc: {value: 'xy', label: ''},
comment: {value: 'comment', label: "" }}
, dx:+20, width:14, r:14,
tip: {format: {x: false, y: false, comment: true}, lineWidth: 20, dx: +15},
Anchor: "bottom", title: (d) => [d.comment].join("\n\n")}),
Plot.text(['Femmes →'], {x: d=> 200000, y: d=>100, dy: -20.5, fontSize: 17}),
Plot.text(['← Hommes'], {x: d=> -200000, y: d=>100, dy: -20.5, fontSize: 17}),
Plot.text(['+'], {x: d=> 15000, y: d=>100, dx: 2, fontSize: 11}),
Plot.text(["Population (en milliers)"], { frameAnchor: "bottom", dy:45, fontSize: 17 }),
Plot.text(["500"], {x: d => -500000, y:d => 0, dy:22, dx: -20}),
Plot.text(["400"], {x: d => -400000, y:d => 0, dy:22, dx: -20}),
Plot.text(["300"], {x: d => -300000, y:d => 0, dy:22, dx: -20}),
Plot.text(["200"], {x: d => -200000, y:d => 0, dy:22, dx: -20}),
Plot.text(["100"], {x: d => -100000, y:d => 0, dy:22, dx: -20}),
Plot.text(["500"], {x: d => 500000, y:d => 0, dy:22, dx: 20}),
Plot.text(["400"], {x: d => 400000, y:d => 0, dy:22, dx: 20}),
Plot.text(["300"], {x: d => 300000, y:d => 0, dy:22, dx: 20}),
Plot.text(["200"], {x: d => 200000, y:d => 0, dy:22, dx: 20}),
Plot.text(["100"], {x: d => 100000, y:d => 0, dy:22, dx: 20}),
]
})