To adapt the code you are using to categorize based on the expression suggested by @JGH, you actually need to create the list of unique values and QgsRendererCategory list based on the expression.
Please try the code below, adapted (and 'Pythonicized') from the logic in the addCategories() method of QgsCategorizedSymbolRendererWidget class which starts at ...
Instead of categorizing the data by intensity, you can categorized it by a concatenation of intensity and affected_p
The expression would be similar to "intensity" || ' - ' || sum("affected_p","intensity")
The example below use the average instead of the sum:
The file bivariate_legend.py has a missing import.
Open file /Users/judithheher/Library/Application Support/QGIS/QGIS3/profiles/default/python/plugins/BivariateLegend/bivariate_legend.py in any editor.
Add from qgis.core import Qgis to the import section.
Restart QGIS and retry. The plugin will run seamlessly.
As commented by @YogeshChavan:
The legend is only active when working in a layout view
and from your comment it looks like when you used your global scene in a map frame on a layout view you were able to insert a legend to go with the layers in it.
As far as I know, the overall size of the legend cannot be forced, and there is no word-wrapping logic (only the labelling engine in the map supports word wrapping, the legend graphic builder is an entirely different animal).
For now, here is a workaround in the form of a Python script. It's quite easy to use. Just paste the script below into a new editor in the Python console, open a print layout, select a legend in the layout, select a layer in the main window Table of contents, then run the script.
open_layouts = iface....
You have to summarize the area by categories, otherwise your expression won't work. As per @Jakobs comment, you have to set this expression in the Legend-tab of the layers properties.
The following should work:
@symbol_label||' ('||sum("area","CODE_18")||' ha)'
This tells QGIS to summarize the field "area" based on the ...
In the main map window (ie not the layout) go to the symbology settings for the layer in question (dNBR in your case), and click in the 'Values' heading in the 'classes' section. That should allow you to order the entries ascending/descending as you wish, without changing the color ramp order.
Then go back to the legend settings of the layout window and ...
Printing layers using clustering will create a client-side image of the layer in the printout.
There is no current support for printing legend items for layers that are sent as a client-...
It seems there is a bug, or maybe intentional behavior where the print widget just sends your layer as a raster layer to the printing server.
The map JSON it is sending is looking at your layer as an image.
It is sending the image in base64:
An other solution from the layer style panel
You can export the color map to a file, reorder the lines with a text editor and import the file again.
Export the color map to a file (1 in the picture)
Open the file, reorder the lines and save the file
Open the file again (2 in the picture)