legend ={
const width = 240;
const svgLegend = d3.create("svg")
.style("width", "200")
.style("height", "100")
const legendGroup = svgLegend.append("g")
.attr("transform", "translate(10, 50)")
.attr('class', 'legend')
legendGroup.append("image")
.attr("width", width)
.attr("height", 8)
.attr("preserveAspectRatio", "none")
.attr("xlink:href", ramp(color.interpolator()).toDataURL());
legendGroup.append("text")
.attr("class", "caption")
.attr("y", -6)
.attr("fill", "#000")
.attr("text-anchor", "start")
.attr("font-weight", "bold")
.text(data.title);
legendGroup.call(d3.axisBottom(d3.scalePoint(["lowest", "median", "highest"], [0, width]))
.tickSize(13))
.select(".domain")
.remove();
return svgLegend.node()
}