qgis – Point Clustering and Legend in QGIS

clusteringlegendpointqgis

I am using the point cluster symbology in QGIS and have defined the size of each point based on the cluster size using @cluster_size in the size assistant.

It looks great on my map, but I cannot figure out how to add the size symbology for the variable to my legend in the map composer to create a map for a presentation/publication.

Best Answer

It's not possible to directly display data-defined symbol sizes in a legend. Here's a workaround.

Duplicate the point layer (Layer panel > right click on layer name > Duplicate layer).

Change symbology of the duplicate layer to "graduated" and for method choose "size."

  • Choose any numerical field for column.
  • Change the "Size from" starting value to 1mm, and the final value to the maximum number of points in a cluster.
  • Change the number of classes to the maximum number of points in a cluster (same as final size value).
  • Click "Classify."
  • Change the legend text as desired, eg "1 point," "2 points" etc.

The style settings for the duplicate layer look like this:

enter image description here

Turn off the duplicate layer so you don't see it on the map.

Use the duplicate layer in the print composer legend. The legend looks like this:

enter image description here

You can use the controls under legend items to

  1. Change the way the layer name is displayed: highlight the layer name, click the pencil icon, type in the name of the original layer.
  2. Delete the name of the field from the legend: highlight the field name, click the red minus sign button.

enter image description here

enter image description here

Related Question