# Re: [R-sig-Geo] Plotting 2 rasters over each other on a map with 2D colour scheme

```Another way of visualising two values per pixel is to vary two of Hue,
Luminance, and Saturation. You can even use all three if you have
three variables!```
```
Note that Hue is a circular variable, and in the example I saw it was
being used to map the seasonal peak of rainfall, so a circular
variable was appropriate (December is close to January). Then I think
saturation was used to indicate total rainfall. So saturated red was
lots of rain, peaking in June, washed out red was low rain also
peaking in June, whereas saturated blue was lots of rain peaking in
March. Unsaturated colours (grey) meant no rain, at which point the
hue was lost but that wasn't a problem because with no rain there's no
peak month.

The examples in the colorplaner package need careful consideration,
because there's no obvious gradient in each of the directions. I don't
think it would be appropriate for my rainfall example above, even
without the circular nature of the peak month variable. Your example
of wanting to look at hot/cold dry/wet extremes would probably suit
the colorplaner palette since the corner extremes are of interest.

I suspect to make such a plot from your two rasters will involve
creating an RGB raster brick by lookup into a 2-d palette from the
values in each of your one-layer rasters....

So given P, an NxN matrix of hexadecimal colour values representing
the palette...

And two rasters A and B scaled to 1:N....

The vector of colours would be P[values(A), values(B)]

Turn that into a 3 layer raster stack and plot with plotRGB.....

Barry

On Thu, Sep 22, 2016 at 2:52 PM, Robin Lovelace <rob...@gmail.com> wrote:
> Hi Vasya
>
> To some extent this is more a visualisation question than a geospatial
> question but is interesting because it's common to want to plot 2 variables
> together. Your question comes at a good time because there has recently
> been published a package for solving precisely this problem: *colorspace*.
>
> https://github.com/wmurphyrd/colorplaner
>
> There are mapping examples in there, but not with raster data. I'm sure you
> could use it to solve your problem, however.
>
> Another approach is to use the magick image manipulation package.
>
> Here's some code and an image showing the result.
>
> Code: https://gist.github.com/Robinlovelace/9d9844886ec186c4423b611e6185392e
>
> Resulting image (sorry about the 'pipes' Edzer!): https://flic.kr/p/Mj5cos
>
> I suggest the colorplane package instead of the *magick* way (unless
> someone knows of a better solution) at present because it also seems to
> create a legend for you.
>
> If you provide a simple, reproducible example to start with, that will
> increase the probability of someone helping out.
>
> On Thu, Sep 22, 2016 at 11:51 AM, Vasya Pupkin via R-sig-Geo <
> r-sig-geo@r-project.org> wrote:
>
>> Hi guys,
>>
>> What I am trying to do is to make a map that would show the areas which
>> are hot-dry, hot-wet, cold-dry, cold-wet. I have 2 rasters with
>> precipitation and temperature values. And I want to plot them over each
>> other so that each extreme combination of the 2 variables (hot-dry,
>> hot-wet, cold-dry, cold-wet) would have its own colour with respective
>> gradients for the intermediate values on the colour scheme, that will have
>> to produce a 2D colour legend. Below please see a link to the concept
>> image, that I have produced for explanation. I saw such a thing once and
>> thought that was a briliant idea to show how 2 variables interact, but then
>> I totally forgot where it was. I have been googling for 2 days - no result.
>> Any help is very much welcome - the name of the thing, name of the software
>> to do it (how to do it would be marvelous), keywords to google, workarounds
>> - anything.
>>
>> Concept image:
>> https://cloud.mail.ru/public/SHno/98X3czaW5
>>
>> Best wishes,
>> Vasya.
>> _______________________________________________
>> R-sig-Geo mailing list
>> R-sig-Geo@r-project.org
>> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>>
>
>         [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
```