6

I'm trying to plot a map of the residuals of a linear model. My residuals centre around zero and can obviously go in either direction.

Is there an easy way to apply a graduated colour scale to these values in QGIS, one that centres on zero and then shades in red above zero and blue below (or whatever colour ramp you choose) without having to manually set the upper and lower limits of each category?

2
  • Seems doable, but for better answer, can you give more precision about your data. An example dataset and/or a screenshot ?
    – Pierma
    Jun 25, 2016 at 2:31
  • The exact distribution isn't so important, you could generate suitable dummy data by creating a column of values based on randbetween(-100,200) in Excel
    – Tumbledown
    Jun 27, 2016 at 8:05

3 Answers 3

4

Kludgy method:

Suppose your residuals go from -1 to +2 (use the "Statist" plugin to get the range of your attribute)

Create a dummy point (or other geometry) with residual -2.

Style as normal with an odd number of categories, white in the middle.

Make your dummy point invisible with some other style rule, or maybe delete it (but don't reclassify!). Or put it far away from your data and zoom until it's not visible.

If residuals go from -2 to +1 the dummy point needs value +2.

1

You can assign a graduated color ramp to a layer in QGIS by choosing it under Layer Properties > Style. Here you can choose a given color ramp with three colors and set the offset of the middle color according to your dataset by editing the color ramp. Now you only have to set the number of classes and it classifies your data automatically.

If this doesn't produce the results you want, another possibility is to split the data layer into two layers, one with the negative values and the other one with the positive ones. Then you can assign each one a separate color ramp which goes only e.g. from red to white.

0

Try adjusting the breaks in the histogram once you've set a graduated colour scheme in the Layer Properties:

Here is the basic symbolization:

enter image description here

Then click the 'histogram' tab and click the 'load values' button:

enter image description here

Now click the histogram above the 0 value on the X axis - this adds a class to your graduated scheme that will start at 0:

enter image description here

That's the closest and easiest way to add a break at 0 - play around with the colour palette you want to use, but that might get you close...

2
  • This is the method I've been using and I suspect it's the easiest out of all the answers suggested so far. It's a shame the x axis doesn't have a snapping option so you can easily get a bin for 0-50 rather than 0.023 - 49.992
    – Tumbledown
    Jun 27, 2016 at 15:21
  • @Tumbledown could be a useful feature request if indeed this works for such a problem! Jun 27, 2016 at 15:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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