{
const svg = d3.create('svg')
.attr('width', width)
.attr('height', height)
.attr('role', 'img');
var title = svg.append('title');
title.text("Scatterplot of all the counties in Saint Paul, Minnesota graphed against Median Income and Media Temperature. We can tell from the scatterplot that the higher the income of the neighborhood, the lower the surface temperature.");
svg.append('g')
.attr('transform', `translate(0, ${height - margin.bottom})`)
.call(d3.axisBottom(x))
.append('text')
.attr('text-anchor', 'end')
.attr('fill', 'black')
.attr('font-size', '12px')
.attr('font-weight', 'bold')
.attr('x', width - margin.right)
.attr('y', -10)
.text('Median Income');
svg.append('g')
.attr('transform', `translate(${margin.left}, 0)`)
.call(d3.axisLeft(y))
.append('text')
.attr('transform', `translate(20, ${margin.top}) rotate(-90)`)
.attr('text-anchor', 'end')
.attr('fill', 'black')
.attr('font-size', '12px')
.attr('font-weight', 'bold')
.text('Median Temperature');
const counties = svg
.selectAll('circle')
.data(finalpro)
.join('circle')
.sort((a, b) => b.MedianTemperature - a.MedianTemperature)
.attr('class', 'country')
.attr('opacity', 0.75)
.attr('cx', d => x(d.MedianHouseholdIncome))
.attr('cy', d => y(d.MedianTemperature))
.attr('fill', 'orange')
.attr('r', 5)
counties
.append('title')
.text(d=> "Neighborhood with median income of " + d["MedianHouseholdIncome"] +" dollars has a surface temperature of " + d["MedianTemperature"] + "degrees in Kelvins");
counties
.on('mouseover', function() {
d3.select(this).attr('stroke', '#333').attr('stroke-width', 2);
})
.on('mouseout', function() {
d3.select(this).attr('stroke', null);
});
return svg.node();
}