To define different styles based on conditions from attribute values, use styling with
Rule based renderer (see docu). You can achieve (almost?) everything you could do with other methods.
You can add as many styles as you want and define for each simple or complex conditions when it should be visible. It will be still one layer only, but with many different styles.
In the layer panel as well as in the Layer styling, you can activate and deactivate each style by clicking the checkbox next to it: see the red arrows in the screenshot.
One layer, styled with four different styles, here based on a filter condition (
Rule) based on the polygon's
Name attribute - you could include other attribute fields to create complex conditions:
Use with scalar attributes: data driven override (manual)
If you have scalar attributes and want to get a graduated style based on the attribute value, you can use data driven override for any part of the style like color, fill style, stroke width, stroke style etc. Set a rule based renderer and then in the style settings, click on the data driven override icon at the right side of the setting options and click on
Then select a source (be it an attribute field or a more complex expression), load min/max values (or enter them manually) and select a color ramp to get a graduated style.
Graduated style: solid fill with a
white-to-blue color ramp, based on the attribute
value (see label for the value for each feature); Storke color and stroke width (border of each polygon) similarily styled based on the same attribute:
Refine selected rules to create categorized or graduated styles (automatic)
You have even more options selecting one rule defined style by selecting one of the three options under
Refine selected rules (right click rule or open it at the bottom of the panel, see screenshot). Here, you can, between elso, choose
Add categories to rule or
Add Ranges to rule to create a style that corresponds to
Graduated layer style rendering.
Graduated style based on the attribute
value, but only for features with
value > 50. I used
Add ranges to rules with the expression
scale_linear( value,50,100,0,100) to "spread" the color ramp (use the full spectrum of the white-to-red color scale) for values from 50 to 100: