const xValue = (d) => d.petal_length; const yValue = (d) => d.petal_width; const speciesValue = (d) => d.species; const marker = (d) => { switch(d){ case 'setosa': return 'skyblue'; case 'versicolor': return 'lightgreen'; default: return 'orange'; } } const marks = data.map((d) => ({ x: x(xValue(d)), y: y(yValue(d)), Species: speciesValue(d), color: marker(speciesValue(d)), })); svg .selectAll('circle') .data(marks) .join('circle') .attr('cx', (d) => d.x) .attr('cy', (d) => d.y) .attr('fill', (d) => d.color) .attr('r', radius);