Reputation: 1247
In R, say you wish to present statistical data on an image background- like in medical imaging
Each layer is a different matrix. Here is a non-sense example:
volcano
in gray B<- (volcano>160) * rnorm(prod(dim(volcano))
in
heat colors. How would you go about?
Upvotes: 3
Views: 2712
Reputation: 49640
The image
function can do this, just set the transparancy of the 2nd set of colors and overlay it using add=TRUE
. Any missing values will be completely transparent and you can set the alpha level for the other colors (of course your graphics device has to support partial transparancy for this to work). Here is a quick example:
A <- t(volcano)[ncol(volcano):1,]
B <- (A>160) * rnorm(prod(dim(A)) )
B[ A < 120 ] <- NA # show some complete transparency
image(A, col=grey( seq(0,1,length.out=12) ) ) # initial plot
hc <- sub('FF$','77',heat.colors(12)) # convert heat colors to have an alpha
image(B, add=TRUE, col=hc) # overlay the new plot
Upvotes: 3