QGIS Symbology – How to Show Both Size and Color of Points in Legend

legendprint-composerqgissymbology

I am working on a project in QGIS (3.28.5-Firenze) and I need to create a map, but I am having some issues with creating a proper legend.

I am working with a point layer, where the points have different colors based on the "category" attribute and different sizes depending on "tons" attribute (the sizes are created by using the following expression

 coalesce(scale_exp("tons", 0, 2.3e+06, 1, 10, 0.5), 0)"))

My problem is that I cannot display the symbology for both in the print layout. I need to remove the size categories in order to show the point colors in the legend, or in order to show the sizes I had to disregard the colors and make new sizes using the symbology tab (I couldn't replicate the sizes exactly, but got close enough by using "Graduated" with Natural Breaks(Jenks)).

Is there a way I can display both the colors for the different categories and the size categories in the legend? Can I do it for just one layer or should I "cheat" and create multiple layers (maybe separate layers for each category)? And in that case how should I go about it?

Any help would be greatly appreciated!

Best Answer

  1. Set a categorized layer styling for your colours
  2. Click the large Symbol button
  3. Use the Data-defined Override to select a field for the size
  4. (or...) Choose Edit to enter an expression

enter image description here

enter image description here

  1. Back on the main Symbology pane, click Advanced > Data-defined Size Legend

enter image description here

  1. Configure the Size Legend

  2. You may have to create Manual size classes, depending on the renderer type.

enter image description here

Resulting legend in Print Layout

enter image description here

Related Question