score:2

Accepted answer

it appears at the top because the 5 is interpreted by the svg as pixel coordinates, so it is at pixel y=5 (svg counts from top to bottom). in your case, the 5 is not in pixel space, but in data space. to convert from the data space to the pixel space you have to use the yscale, the same way you do with the circles on the scatterplot:

var yaveline = function(d) {
  return yscale(data[0].yave);
}

this will convert data[0].yave from data to pixel, that is, it will return the pixel that is associated with the data value.


Related Query