Rendering based on cluster size in ovito

I want to generate an image as shown in the picture:
5
I selected Sort clusters by size in Cluster lysis, and then selected Cluster in the Input property of Color coding, but the generated image did not render particles according to the size of the clusters. The legend I generated also shows Cluster instead of Cluster Size. How can I generate the above image?
6

Color coding particles based on the size of the cluster they belong to involves the following steps:

  1. Add a Cluster Analysis Modifier:
    This step generates the following information:

    • a particle property called Cluster, which assigns each particle a unique cluster identifier and
    • a data table called Cluster list, which provides the size of each cluster along with its corresponding cluster ID.
  2. Create a custom particle property using a Python Script modifier:
    Generate a new particle property called Cluster size, which maps the size of each cluster to particles based on their Cluster ID, e.g.:

    def modify(self, data: DataCollection, *, frame: int, **kwargs):
        cluster_sizes = data.tables['clusters']['Cluster Size']
        data.particles_.create_property("Cluster size", data=cluster_sizes[data.particles.cluster-1])
  1. Apply a Color Coding Modifier:
    Use the Cluster size property created in the previous step as the input for the Color Coding modifier to visually differentiate particles by cluster size.
  2. (Optional) Add a Color Legend Overlay:
    Add a Color Legend visual overlay to your viewport to display the color map in the rendered image, making the representation more informative.

Please also refer to the linked manual entries for further information.