Note that there are some explanatory texts on larger screens.

plurals
  1. POcategorical scatter plot using d3.js javascript
    primarykey
    data
    text
    <p>I need to make a scatter plot for some categorical data for rainfall in 3 cities for 3 years using d3.js:</p> <pre><code>Year1 Year2 Year3 NY CA TX NY CA TX NY CA TX 17 20 15 23 10 11 14 15 17 16 18 12 15 21 22 20 18 19 13 22 16 17 25 18 17 25 18 19 18 13 16 21 20 22 15 16 </code></pre> <p><img src="https://i.stack.imgur.com/XCQqX.png" alt="This is how the graph should look like"> (Note: the data and plot do not match here, it is just to explain my query) I am completely new to d3.js. I have attempted some tutorials for simple scatterplots and bar graphs, but I can't figure out how do I display a categorical graph like this one.</p> <p>Any help to get me started would be appreciated.</p> <p>[edit] I rearranged the data in the tsv file so it looks like this:</p> <pre><code>year state rain 1 NY 17 1 NY 16 1 NY 13 1 CA 20 1 TX 15 2 NY 23 3 CA 10 3 TX 14 3 NY 13 </code></pre> <p>There seems to be some problem. I get "Unexpected value NaN parsing cx attribute." and same for cy. Any idea how can I fix it?</p> <pre><code>var newArray = new Array(); // draw the scatterplot svg.selectAll("dot") // provides a suitable grouping for the svg elements that will be added .data(data) // associates the range of data to the group of elements .enter().append("circle") // adds a circle for each data point .attr("r", 5) // with a radius of 3.5 pixels .attr("cx", function (d) { newArray = data.filter( function (el) { return el.category == "NY"; }); return xScale(newArray.rain); }) // at an appropriate x coordinate .attr("cy", function (d) { return yScale(newArray.year); }) // and an appropriate y coordinate .style("fill", color(9)); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload