Let's say I have a dataset of different athletes that perform the same test on different days. On each day, they will have several trials/runs. I want to visualise each athlete's development across these days using d3.js but I'm struggling to understand how I can accomplish this task.
Using seaborn in Python or ggplot2 in R, I would have used a facetplot where each day is a facet. Within these facets, I would have the trials on the x-axis and the performance on the I axis. But how can I do this in d3.js?
The d3.group and group allow me to group the dataset by athletes and I understand how I can iterate over each athlete's values. But I don't understand how I can go from here to actually creating a facetplot in d3.js.
I have tried to search for related tutorials on observable but without much luck. One interesting and related visualisation is[Trumps Golfs bt Bostock]. Another one is this scatterplot.
Could someone please help me in the right direction? I have created a simple dataset and scatterplot that may serve as a starter
const data = d3.range(10).map(i => ({
bib: Math.floor(i / 5) + 1,
ratio: -1 + Math.random() * 5,
run: [1, 2, 3, 4, 5][i % 5],
run: [1, 2, 3, 4, 5][i % 5],
name: ['GIRL1', 'GIRL2', 'GIRL3', 'GIRL4'][Math.floor(i / 5)]
}));
const width = 250;
const height = 150;
const svg = d3.select('svg')
.attr('width', width)
.attr('height', height)
const margin = {
top: 20,
right: 20,
bottom: 20,
left: 50
}
const innerWidth = width - margin.left - margin.right;
const innerHeight = height - margin.top - margin.bottom;
const xScale = d3.scaleLinear()
.domain(d3.extent(data, d => d.run))
.range([0, innerWidth])
const yScale = d3.scaleLinear()
.domain(d3.extent(data, d => d.ratio))
.range([0, innerHeight])
const g = svg.append('g')
.attr('transform', `translate(${margin.left},${margin.top})`)
g.selectAll('circle')
.data(data)
.join('circle')
.attr('r', 3)
.attr('cx', d => xScale(d.run))
.attr('cy', d => yScale(d.ratio))
g.append("g")
.call(d3.axisBottom(xScale))
.attr('transform', `translate(0,${innerHeight})`);;
g.append("g")
.call(d3.axisLeft(yScale))
<script src="https://unpkg.com/d3@6.2.0/dist/d3.min.js"></script>
<svg></svg>
Plot example from R:


