owid / owid-grapher

A platform for creating interactive data visualizations
https://ourworldindata.org
MIT License
1.4k stars 228 forks source link

LineChart: colouring datapoints by categorical indicators, disconnected datapoints #2824

Closed lucasrodes closed 10 months ago

lucasrodes commented 1 year ago

Core problem

video-summary of the issue

Sometimes (not often), we want to build specific LineCharts, where the data points are disconnected from each other or coloured by a categorical variable.

This would allow us to quickly generate interactive charts from charts like this one:

image

The current workaround

Taking the example above, for each year, we plot the datapoint of the maximum life expectancy, coloured by the country it was registered in.

The result is this one, implemented in https://github.com/owid/etl/pull/1835:

highest-life-expectancy-females

This is achieved by using a ScatterPlot instead:

Note that we are forcing the ETL dataset into a specific structure to fit Grapher's needs. Also, we assume that there will only be one data point for a given year, which is not required from ScatterPlots (but from LineCharts).

Proposed solution

While we have a workaround, we could improve the experience so that we don't have to adapt ETL datasets to specific formats to generate the desired plot.

Instead, I think we should:

  1. Have an option to 'disconnect datapoints' in LineCharts. We are nearly there with the "Is projection" checkbox; the only downside for our use case is that checking it adds a "Projected data" label in the tooltip, which is not what we want here. image
  2. Enable colouring by categorical variable. Currently, we can plot lines by a numerical indicator (there is a "Color" section under the "Basic" tab). However, It'd be cool to colour lines also by categorical indicators. Although you can select categorical variables, it does not work at the moment, and the legend is shown on top, which I am not sure is what we'd want: image
  3. It'd be nice to gave the means to tweak the size of the data points, too. Not only in the same way we do it for ScatterPlots (i.e. by an indicator's values), but by a constant value (i.e. increase the size of all data points the same scale).

For my particular case, I think that just by implementing 1. it would suffice. However, I find 2. also valuable for other instances.

lucasrodes commented 1 year ago

Video-summary of the issue

https://github.com/owid/owid-grapher/assets/18101289/c7e8a573-69a3-40a3-bef1-6e022cbba7f0

danyx23 commented 10 months ago

@lucasrodes if we were to do this we'd do it as a new chart type but for that we'd need more motivation than just this one example. Do you know of other non-connected line chart cases? Closing this as wontfix for now but please reopen it if you think there are several other cases like this