Polar Scatter Chart for Wind Direction and Speed
If you are a site planner choosing where to put a turbine, the question you bring to the wind data is which way the strong wind blows from, and how often. A table of readings with a direction and a speed on every row will not show you that. You want to see where the dots gather.
A polar scatter chart answers it. Each reading is a dot placed at its bearing around the circle, clockwise from north, and as far from the centre as its speed. A prevailing wind shows as a cluster of dots far out on one side. The chart above is bound to the grid beneath it, one row per reading, so filtering the rows redraws the dots. Filter the Season column and see whether the prevailing direction holds all year.
Why a polar scatter chart and not a scatter chart
Direction is a circle: 359 degrees is next to 1 degree. A plain scatter chart puts north at both edges, so a wind that swings across north looks like two unrelated groups at opposite ends of the axis. Around a circle the swing stays in one place, and the compass directions mean what they mean on a map.
The chart over a grid
Name the bearing column in x and the speed column in y, and say what the angle column means with polar.angle. Here it is 'degrees', so a value of 370 is read as 10. Polar scatter is an opt-in chart type, so you import its module once after the charts module. Here is the example in plain JavaScript, with sample rows inline in place of your own.
import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
import '@toclocoinc/lattice-grid/modules/chart-polarscatter';
const rows = [
[200, 6.1, 'Winter'], [215, 7.4, 'Winter'], [230, 8.8, 'Winter'], [225, 10.2, 'Winter'],
[20, 3.1, 'Winter'], [210, 8.1, 'Spring'], [235, 7.2, 'Spring'], [300, 4.8, 'Spring'],
[45, 3.6, 'Spring'], [220, 6.9, 'Spring'], [225, 4.4, 'Summer'], [240, 5.0, 'Summer'],
[150, 3.3, 'Summer'], [280, 3.7, 'Summer'], [90, 2.2, 'Summer'],
].map(([direction, speed, season], i) => ({ id: i + 1, direction, speed, season }));
const gridEl = document.createElement('div');
const chartEl = document.createElement('div');
gridEl.style.height = '240px';
chartEl.style.height = '420px';
document.body.append(gridEl, chartEl);
const grid = createGrid(gridEl, {
rowKey: 'id', rows,
columns: [
{ field: 'direction', title: 'Direction (degrees)', type: 'number' },
{ field: 'speed', title: 'Speed (m/s)', type: 'number' },
{ field: 'season', title: 'Season', filter: { type: 'set' } },
],
});
createChart({ grid, container: chartEl, type: 'polarScatter', x: 'direction', y: 'speed',
polar: { angle: 'degrees' }, title: 'Wind speed by direction' });
The same thing in React
The React adapter is a factory, so you build the component once at module scope. The ref’s grid is the real grid, which is what the chart binds to.
import React, { useEffect, useRef } from 'react';
import { createGrid } from '@toclocoinc/lattice-grid';
import '@toclocoinc/lattice-grid/css';
import { createLatticeGrid } from '@toclocoinc/lattice-grid/modules/react';
import { createChart } from '@toclocoinc/lattice-grid/modules/charts';
import '@toclocoinc/lattice-grid/modules/chart-polarscatter';
const LatticeGrid = createLatticeGrid({ React, createGrid });
const rows = [
[200, 6.1, 'Winter'], [215, 7.4, 'Winter'], [230, 8.8, 'Winter'], [225, 10.2, 'Winter'],
[20, 3.1, 'Winter'], [210, 8.1, 'Spring'], [235, 7.2, 'Spring'], [300, 4.8, 'Spring'],
[45, 3.6, 'Spring'], [220, 6.9, 'Spring'], [225, 4.4, 'Summer'], [240, 5.0, 'Summer'],
[150, 3.3, 'Summer'], [280, 3.7, 'Summer'], [90, 2.2, 'Summer'],
].map(([direction, speed, season], i) => ({ id: i + 1, direction, speed, season }));
const columns = [
{ field: 'direction', title: 'Direction (degrees)', type: 'number' },
{ field: 'speed', title: 'Speed (m/s)', type: 'number' },
{ field: 'season', title: 'Season', filter: { type: 'set' } },
];
export function WindRose() {
const gridRef = useRef(null);
const chartRef = useRef(null);
useEffect(() => {
const chart = createChart({ grid: gridRef.current.grid, container: chartRef.current,
type: 'polarScatter', x: 'direction', y: 'speed', polar: { angle: 'degrees' },
title: 'Wind speed by direction' });
return () => chart.destroy();
}, []);
return (<>
<LatticeGrid ref={gridRef} rowKey="id" columns={columns} rows={rows} style={{ height: 200 }} />
<div ref={chartRef} style={{ height: 360 }} />
</>);
}
The options used
These are the rows of the charts reference for the options in the listings above.
| Option | Type | What it does |
|---|---|---|
grid |
Grid | Required. The grid to read. |
container |
Element or string | Required. Where to draw. |
type |
string | 'polarScatter' here, one dot per row. |
x |
string | The column that sets each dot’s angle. |
y |
string | The column that sets each dot’s distance from the centre. |
polar.angle |
string | What the angle column means: 'degrees', 'category', 'hourOfDay', 'dayOfWeek' or 'month'. |
title |
string | Drawn above the plot. |
Reading the cluster
Look first at where the dots reach furthest from the centre, then at how tightly they gather. In the example, the fast readings sit to the south west, which tells you which way the turbine should face and which side needs clear ground. Filter the Season column to see whether that direction holds in summer as well as winter, and clear the filter to see all of the readings again. A row whose direction or speed is missing is not drawn at an invented position, so a gap in your data never becomes a false cluster.
Next
See the polar scatter beside the other circular charts in the polar family demo, read the full list of chart types on the charts page, or follow the how-to for a chart that follows the grid.