0

I have found that one could use a bivariate choropleth to display the values of two rasters in one. For instance: https://flowingdata.com/2015/03/13/bivariate-choropleth-how-to/

I wonder if r has a package to display the values of three rasters?

In this case, the scale could be a rgb cube, like

http://www.dig.cs.gc.cuny.edu/manuals/Gimp2/Grokking-the-GIMP-v1.0/node50.html ,

where the scale of the three-variate raster is the combination of the red, green, blue colors for each of the three rasters independently ?

I have been trying to generate the cube (combining all RGB values) to use that as the scale. but unfortunately, the file gets to be very big:

require(reshape2)
library(rgl)
Cols<-data.frame()

for (blue in 0:255)
{
rg <- outer(0:255, 0:255, rgb, blue=blue, maxColorValue = 255)
rg <-data.frame(blue,melt(rg))
colnames(rg)<-c("blue","red", "green","col")
Cols<-rbind(Cols,rg)
}

plot3d(Cols$blue, Cols$red, Cols$green, col=Cols$col)

1 Answers1

0

I think the plotRGB() function of the raster package will do what you need. See here for an example with a simulated stack of three raster layers:

set.seed(1002)

library(raster)

r1 <- raster(matrix(rnorm(10000), 100, 100))
r2 <- raster(matrix(rnorm(10000), 100, 100))
r3 <- raster(matrix(rnorm(10000), 100, 100))

s <- stack(r1, r2, r3)

plotRGB(s, stretch='hist')
Robert Hijmans
  • 40,301
  • 4
  • 55
  • 63
Forrest R. Stevens
  • 3,435
  • 13
  • 21
  • Thank you for the edit Robert (and for all of your time spent developing the `raster` package, it's invaluable to our community and to my work). – Forrest R. Stevens May 09 '15 at 20:47
  • is there any way to generate the scale (legend) of such a three-variate raster? I presume it should be like a cube? library(squash) provides a function "cimage" that could be used to generate the legend for a bi-variate scale. – user3029447 May 10 '15 at 00:14
  • You can easily generate a triangle plot representing the color mixes of RGB using some simple simulated data and raster algebra. This has been asked before on StackOverflow so hopefully [this would get you started](http://stackoverflow.com/questions/11777124/three-way-color-gradient-fill-in-r). – Forrest R. Stevens May 10 '15 at 01:24