3

In QGIS (using ver. 3.16) , you can use the categorized symbology renderer for polygons to assign a certain color to polygons with the same attribute value. There is also the Topological coloring algorithm to assign a value to each polygon in such a way that no adjacent polygons share the same color. Both works perfect.

However, I want to have a "nested" coloring of polygons - in the same style as this map here: https://i.stack.imgur.com/rgiqh.jpg

So there should be a main color for the first order territorial units (say: blue, green, red), whereas all subordinated second order terrritorial units should be assigned a variation of this basic color (like: dark, light... blue, green, red).

A workaround would be to treat each first order territorial unit separately as an own layer and apply to each a categorized styling, using diffent color-ramps: blues, greens, reds. But this is quite cumbersome.

Is there a better way to achieve this?

enter image description here

3 Answers 3

5

A bit of a work-around but you could split the data into two layers if its not already and do a monochrome scheme (greys ramp) with the subordinate areas and then a semi-transparent colour scheme for the primary "first-order" areas. Putting the semi-transparent coloured layer on top would give the intended look of what you're going for without so much manual colour assignment in the symbology editor.

2
  • I'm not sure if I understood you well. If I apply a monochrome scheme to the subordinate areas, I have dozens of barely distinguishable shades of gray all over the map. However, I want to have a clearly diffenrentiated color-scheme (say: from light to dark) inside of each second order area (polygon). So the question to your solution would be: how to realise a full black-to-white color-scheme for each subordinate area?
    – Babel
    Nov 3, 2020 at 14:24
  • 1
    By the way, once realised such a black-to-white-scheme, adding another coloured layer as you propose works. However, using blending modes instead of transparency is nicer. Using overlay or multiply blending mode the colors are not so pale as with transparency. Unofortunately, I'm not able to add screenshots here in the comment.
    – Babel
    Nov 3, 2020 at 14:25
3

Thanks to the combination of the answers offered here, there is a solution to almost automatize what I want to achieve. First, set a grayscale value in the layer that contains the second order territorial units. For that, I used the solution proposed by @JGH in another post. The second part, using colors, is from @Lisa's proposal.

Since not all first order territorial units contain the same number of sub-units, I had to convert the ID created in such a way that each first order territorial unit contains the whole range of grayscales (from completely black to completely white, thus from 0% to 100% black). To convert the ID in such a way, I exported the virtual layer to a normal layer, than created a new field called grayscale with the field-calculator, calculating values from 0 to 100 for each unit from the value-range of the newID.

The expression looks like this - I used (newID-1) to get a zero-value for the first ID. Than calculating the range in such a way that: first_ID in every unit =0, last_ID in every unit =100:

ID * 100 / number of units

This is how the expression looks like:

("newID"-1) *100/(  count( "newID", group_by:= "my_first_order_units")-1)

Thus I created a new field grayscale. Now, I simply define the color with a data-driven override - assistant - choose/define a color ramp from black to white - the grayscale field as source - apply.

This looks like this - the label indicates the newID:

enter image description here

Now adding the layer for the first order territorial units in categorized colors, as proposed by @Lisa:

enter image description here

And now combining the two layers, using layer blending modes (e.g. overlay or multiply):

Overlay: enter image description here

Multiply: enter image description here

1

For a handful of different main colors, you can use a rule based style with nested color ramps.

Start by applying a style of type categorized on the main attribute.

Change the style to be rule-based (it will have rules for every attributes from the previous step, saving a bit of time).

For each rule (== main category), right click and select refine current rule / add categories to rule. Select the sub-attribute. Select a color ramp of your choice (all blue, all red etc). Click classify, go back to the main style (that is, click the go back triangle at the top of the sub-rules, else the style will not be applied).

Bear in mind that, for the color ramp, all values will be used to establish the possible values, even the ones for a different main category. You may have to adjust the acceptable values (i.e. remove sub-categories) then re-apply the color ramp.

Your Answer

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

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