ImperialCollegeLondon / gridlington-vis

BSD 3-Clause "New" or "Revised" License
1 stars 0 forks source link

Use proportional representation for waffle charts #104

Closed tsmbland closed 10 months ago

tsmbland commented 10 months ago

Description

Waffle charts were previously using one square per agent, which looked very cluttered. To fix this we needed a way of grouping agents into squares so that each square represents more than one agent.

I'm using a proportional representation algorithm usually used for election voting to allocate a large number of votes to a relatively smaller number of seats. This can be generalised to allocate a large number of agents to a relatively smaller number of squares.

The create_waffle_chart function now has an option to specify the total number of squares in the chart. If this is different from the total number of agents, it will use the proportional representation algorithm to allocate agents to the squares.

In this case I'm using 546 for the total number of squares for consistency with the EV chart (546 is the total number of EVs, so the EV chart doesn't use proportional representation (1 square = 1 EV)). I'm also manually setting the number of rows in both charts to avoid the irregular shape seen before (charts are now 21x26).

We still have the issue in the agent chart where the total number of agents is changing at each timepoint (albeit less visible now). Presumably this shouldn't be the case and suggests a problem with the data. This is something we will have to bring up with Yue.

Before

Screenshot 2023-12-05 103806

After

Screenshot 2023-12-05 112316

Close #80

Type of change

Key checklist