I have 80 sites with percentage of landmanagement and individual numbers of beetles.

I would like to visualise the number of individuals with a diagram (histogram, bar length, see below left diagram) and at the same time the percentage of management by colour (e.g. light blue 0% dark blue 100%, see scale below, right side).

Is there a way to combine these two by e.g. set a rule-based colour in the diagrams? I tried by adding attributes, but then I got more bars. I just want to adjust the colour of the individual numbers using the attribute percentage of management.

enter image description here enter image description here

enter image description here

  • Please provide a screenshot of what you're talking about, as well as what you tried so far.
    – Erik
    Commented Nov 22, 2022 at 11:05
  • o.k. I edited the question
    – oppia04
    Commented Nov 22, 2022 at 11:17
  • 1
    Cartographically speaking ... your bars are actively prohibiting the viewer from understanding the map. It would be way easier to understand your data if you used points in order to display the location, controlled their colour by graduated symbology and labelled them with the number of beetles.
    – Erik
    Commented Nov 22, 2022 at 12:08

1 Answer 1


To do this you need to set the fill colour of the boxes using an expression:

enter image description here

Then you need to use the color_ramp() function to choose a colour ramp that you like (e.g. 'Blues') and use your attribute to pick a position along that colour ramp, positions along colour ramps range from 0 to 1. So first you will have to use a function to convert your attribute (percent of management, I'm going to call this "management_percent" in the expression) to a 0 to 1 scale. So, with that, use this expression:

ramp_color('Blues', scale_linear("management_percent", 0, 100, 0, 1))

  • 1
    Alternatively one could run something like ramp_color('Blues',"management_percent"/100). Or does the scale_linear do something relevant for the expression besides normalizing it?
    – Erik
    Commented Nov 22, 2022 at 15:11
  • 1
    @Erik in the case of this particular question "management_percent"/100 would work fine because it is a value between 0 and 100 (assuming OP's value don't range beyond that), however scale_linear() would work for any range of values so it is more broadly applicable. It would still work if you had values between 50 and 1000 for example while dividing by 100 would not. Commented Nov 23, 2022 at 9:09
  • 1
    Thank you for the explanation =)
    – Erik
    Commented Nov 23, 2022 at 9:34
  • Thank you for this cool way of editing styles that I wasn´t aware of. But your example works for me only for the simple marker of the layer symbology but it isn´t possible to set the colour of the diagram-boxes in this way or did I get something wrong? For the layer symbology I would have no problem by using rule-based symbologies
    – oppia04
    Commented Nov 25, 2022 at 8:22
  • @oppia04 sorry I don't understand your question. How are you histogram boxes set up? Can you edit your question to include a screen shot of the symbology properties please? Commented Nov 25, 2022 at 9:17

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.