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!

1 Answer 1

  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

  • Hi, thank you so much for your answer! I have one question about your approach... I have no idea which values I should put for the "Value" and "Label" in the last part. What do those two things signify?
    – H. Lange
    Commented May 25, 2023 at 12:24
  • The sizes in my case were created with the expression I showed in the question and the values of the attribute used to determine the size are [2300000, 243269, 80000, 60000, 47250, 46800, 38453, 25594, 25000, 15750, 14000, 13190, 7875, 7500, 6243, 5316] if that is useful
    – H. Lange
    Commented May 25, 2023 at 12:25
  • They are basically class breaks for the different size circles. The value is the size that the circle gets rendered, and the label is the text that appears beside the legend. There are several orders of magnitude between your smallest and largest values so you may want to try a logarithmic scale. I just realised there is a mistake in my screenshot - the label for 2 should be 2, not 0!
    – Matt
    Commented May 25, 2023 at 12:29
  • So are they they upper or lower bound of the class break? As far as I can see I can only input one number
    – H. Lange
    Commented May 25, 2023 at 12:46
  • Upper. For example, if the size of your circle for 60000 is 20 (mm) then you set value to 20 and label to 60000
    – Matt
    Commented May 25, 2023 at 12:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.