Skip to main content
Public

Share visualization

Loading preview…

Added Interaction in Scatterplot of Intentional Homicides

vizhub.com

Shared links may look like this on X, LinkedIn, Slack, and Discord.

Before sharing, review the publishing checklist.

Choose how to deliver this visualization

LinkedIn caption

LinkedIn may not keep text supplied by the share sheet. Copy the caption and paste it into the post if needed. You can tag the VizHub company page when posting.

More options

Embed on a websiteCopy iframe embed code
Download & exportPNG, HTML, source ZIP

Added Interaction in Scatterplot of Intentional Homicides

0
LLilly-beth Linnell
Last edited Dec 10, 2021
Created on Nov 4, 2021

This scatterplot displays UN intentional homicide data, plotting homicide values against year for each country. A Voronoi overlay, created with d3.Delaunay, enables interactive tooltips that reveal the country name when hovering over a data point. The visualization uses D3 v6 to render SVG circles and axes, with the Voronoi cells ensuring precise hover detection even for overlapping points.

AI-generated description

My iteration of me original scatterplot using the UN Intentional Homicide dataset.

It isn't perfect, I still haven't figured out how to make the country names more clear,

Based on the comment from a classmate: "Hello Lilly-beth, I was looking through your scatterplots and found the first one about homicide rates to be particularly interesting. I think if you decide to keep that viz as a scatterplot for your final project, an interesting iteration would be to highlight the outliers (perhaps display the name of the country, and the homicide count by gender for each). I noticed that there is a rather extreme outlier in 2003 and I would be interested in knowing which country that was. From there it would be interesting to see why it became such an outlier that year (if there was a war going on, or something)."

const voronoi = d3.Delaunay .from(data, d => x(d.Year), d => y(d.Value)) .voronoi([margin.left, margin.top, width - margin.right, height - margin.bottom]); // ensures voronoi is limited to the chart area

svg.append("g") .attr("class", "voronoiWrapper") .selectAll("path") .data(data) .join("path") .attr("opacity", 0.5) .attr("stroke", "#ff1493") // Hide overlay .attr("fill", "none") .style("pointer-events", "all") .attr("d", (d,i) => voronoi.renderCell(i)) .on("mouseover", (d, i) => { if (d.y > 1) { svg.append('g') .attr("class", "tooltip") .attr("transform", translate(${y(d.y)})) .call(popover, Country Name: ${d.x.toLocaleString(undefined, {Sex: "short", Crime: "numeric", year: "numeric"})} ${d.Country}) } }) .on("mouseout", () => svg.selectAll('.tooltip').remove());

Comments

Sign in to join the discussion.

MIT Licensed