{
const height = 400,
marginBottom = 50,
marginTop = 20,
marginLeft = 70;
const extent2 = d3.extent(data, (d) => d.efficiency);
const second = d3.scaleLinear(extent2, [height - marginBottom, marginTop]);
const remap = d3.scaleLinear(extent2, [
0 ,
d3.max(data, (d) => d.sales)
]);
const w = Math.min(width, 780);
return Plot.plot({
marginLeft,
marginRight: 50,
marginBottom,
marginTop,
width: w,
height,
x: { tickRotate: -45, tickFormat: "" },
y: { axis: "left" },
marks: [
Plot.barY(data, { x: "year", y: "sales", fill: "#ccc" }),
[
() =>
d3
.create("svg:g")
.attr("transform", `translate(${w - marginLeft + 10})`)
.call(d3.axisRight(second))
.call((g) =>
g
.append("text")
.text("↑ efficiency")
.attr("fill", "steelblue")
.attr("transform", `translate(0,${marginTop - 10})`)
)
.node(),
Plot.line(data, {
x: "year",
y: (d) => remap(d.efficiency),
stroke: "steelblue",
strokeWidth: 2.5,
marker: "circle"
})
]
]
});
}