# Plotting / Y axis, values not ordered

**URL:** <https://talk.observablehq.com/t/plotting-y-axis-values-not-ordered/6566>\
**Category:** Help\
**Created:** [May 17, 2022, 7:27am UTC](https://talk.observablehq.com/t/plotting-y-axis-values-not-ordered/6566 "2022-05-17T07:27:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bttgcm](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bttgcm/32/6357_2.png) [@bttgcm](https://talk.observablehq.com/u/bttgcm)\
**Post date:** [May 17, 2022, 7:27am UTC](https://talk.observablehq.com/t/plotting-y-axis-values-not-ordered/6566/1 "2022-05-17T07:27:44Z")

</div>

Hi everyone,  
the solution to this problem is probably very simple but being new to Observable I am struggling to find it.

I am plotting a correlation between two column from a .csv file.  
One column is not understood as numeric (would this be the cause?) and values are not ordered.  
I am not sure if I am doing something wrong when importing it, or I miss additional parameters when writing the plot function.  
Would you have any suggestion?

See [notebook](https://observablehq.com/@bttgcm/akaki-water-quality)

Thank you

---

<div class="post-metadata">

**Author:** ![Fil](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/fil/32/207_2.png) [@Fil](https://talk.observablehq.com/u/Fil)\
**Post date:** [May 17, 2022, 7:57am UTC](https://talk.observablehq.com/t/plotting-y-axis-values-not-ordered/6566/2 "2022-05-17T07:57:49Z")

</div>

it’s probably because of the values marked “\_”, which are understood as strings and make _y_ defaulting to an ordinal scale.

You can try to specify `y: { type: "linear" }`

---

<div class="post-metadata">

**Author:** ![bttgcm](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bttgcm/32/6357_2.png) [@bttgcm](https://talk.observablehq.com/u/bttgcm)\
**Post date:** [May 17, 2022, 8:06am UTC](https://talk.observablehq.com/t/plotting-y-axis-values-not-ordered/6566/3 "2022-05-17T08:06:21Z")

</div>

Solved, thank you.  
If I understand correctly, I should avoid “\_” in column names.

---

<div class="post-metadata">

**Author:** ![mbostock](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/mbostock/32/9_2.png) [@mbostock](https://talk.observablehq.com/u/mbostock)\
**Post date:** [May 17, 2022, 1:07pm UTC](https://talk.observablehq.com/t/plotting-y-axis-values-not-ordered/6566/4 "2022-05-17T13:07:05Z")

</div>

The problem isn’t the column names or the underscores; it’s the type of the values. Even though you’re using {typed: true} to load your CSV, the format of the numbers doesn’t match the requirements of d3.autoType, and so some of your numeric columns are still represented as strings. Note the quotes here on the “EC” and “COD mg/l” columns:

 ![Akaki Water Quality bttgcm Observable](https://canada1.discourse-cdn.com/flex030/uploads/observablehq/original/2X/4/404e2ecd09dd3890bedecedbcd52de5c6aadd15f.jpeg)

That’s most likely because these columns have numbers formatted with commas. To fix this, you should either correct the formatting in your CSV file (removing the commas), or you should use _array_.map after loading the CSV to coerce the numeric strings to numbers.

Plot infers the type of the column from the type of the values: if you give it strings, it’ll assume you have ordinal data rather than numeric data. Adding `type: "linear"` to the scale definition as @Fil suggests will tell Plot to explicit coerce the string values to numbers. However, Plot’s coercion logic (which simply uses JavaScript’s coercion logic) will consider any number with a comma in it as NaN, and that will get dropped from your dataset. So I don’t recommend that. (Sorry, Fil!)

Here’s how to change your `dataset` definition to fix the types:

```nohighlight
dataset = {
  const data = await FileAttachment("Akaki_WQ-1.csv").csv({typed: true});
  for (const column of data.columns) {
    for (const d of data) {
      // If any string values appear to be comma-formatted numbers,
      // remove the commas and then coerce them to proper numbers.
      if (typeof d[column] === "string" && /^(\d|,)+(\.\d+)?$/.test(d[column])) {
        d[column] = +d[column].replace(/,/g, "");
      }
    }
  }
  return data;
} 

```

Suggestion: [Comparing Akaki Water Quality to Akaki Water Quality / Observable](https://observablehq.com/compare/dd37840038b397e4...9de00997f633c18c)
